1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the documentation of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:FDL$
10 ** GNU Free Documentation License
11 ** Alternatively, this file may be used under the terms of the GNU Free
12 ** Documentation License version 1.3 as published by the Free Software
13 ** Foundation and appearing in the file included in the packaging of
17 ** Alternatively, this file may be used in accordance with the terms
18 ** and conditions contained in a signed written agreement between you
26 ****************************************************************************/
30 \title Qt Declarative Module
33 \brief The Qt Declarative module provides a declarative framework
34 for building highly dynamic, custom user interfaces.
36 To include the definitions of the module's classes, use the
40 #include <QtDeclarative>
43 To link against the module, add this line to your \l qmake \c
50 For more information on the Qt Declarative module, see the
51 \l{Qt Quick} documentation.
56 \macro QML_DECLARE_TYPE()
57 \relates QDeclarativeEngine
59 Equivalent to \c Q_DECLARE_METATYPE(TYPE *) and \c Q_DECLARE_METATYPE(QDeclarativeListProperty<TYPE>)
61 #include <QtDeclarative> to use this macro.
65 \macro QML_DECLARE_TYPEINFO(Type,Flags)
66 \relates QDeclarativeEngine
68 Declares additional properties of the given \a Type as described by the
71 Current the only supported type info is \c QML_HAS_ATTACHED_PROPERTIES which
72 declares that the \a Type supports \l {Attached Properties}.
74 #include <QtDeclarative> to use this macro.
79 \fn int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
80 \relates QDeclarativeEngine
82 This template function registers the C++ type in the QML system with
83 the name \a qmlName, in the library imported from \a uri having the
84 version number composed from \a versionMajor and \a versionMinor.
86 Returns the QML type id.
88 There are two forms of this template function:
92 int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName);
94 template<typename T, int metaObjectRevision>
95 int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName);
98 The former is the standard form which registers the type \e T as a new type.
99 The latter allows a particular revision of a class to be registered in
100 a specified version (see \l {QML Type Versioning}).
103 For example, this registers a C++ class \c MySliderItem as a QML type
104 named \c Slider for version 1.0 of a \l{QML Modules}{module} called
105 "com.mycompany.qmlcomponents":
108 #include <QtDeclarative>
112 qmlRegisterType<MySliderItem>("com.mycompany.qmlcomponents", 1, 0, "Slider");
115 Once this is registered, the type can be used in QML by importing the
116 specified module name and version number:
119 import com.mycompany.qmlcomponents 1.0
126 Note that it's perfectly reasonable for a library to register types to older versions
127 than the actual version of the library. Indeed, it is normal for the new library to allow
128 QML written to previous versions to continue to work, even if more advanced versions of
129 some of its types are available.
133 \fn int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& message)
134 \relates QDeclarativeEngine
136 This template function registers the C++ type in the QML system with
137 the name \a qmlName, in the library imported from \a uri having the
138 version number composed from \a versionMajor and \a versionMinor.
140 While the type has a name and a type, it cannot be created, and the
141 given error \a message will result if creation is attempted.
143 This is useful where the type is only intended for providing attached properties or enum values.
145 Returns the QML type id.
147 #include <QtDeclarative> to use this function.
149 \sa qmlRegisterTypeNotAvailable()
153 \fn int qmlRegisterTypeNotAvailable(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& message)
154 \relates QDeclarativeEngine
156 This function registers a type in the QML system with the name \a qmlName, in the library imported from \a uri having the
157 version number composed from \a versionMajor and \a versionMinor, but any attempt to instantiate the type
158 will produce the given error \a message.
160 Normally, the types exported by a module should be fixed. However, if a C++ type is not available, you should
161 at least "reserve" the QML type name, and give the user of your module a meaningful error message.
163 Returns the QML type id.
168 #ifdef NO_GAMES_ALLOWED
169 qmlRegisterTypeNotAvailable("MinehuntCore", 0, 1, "Game", "Get back to work, slacker!");
171 qmlRegisterType<MinehuntGame>("MinehuntCore", 0, 1, "Game");
175 This will cause any QML which uses this module and attempts to use the type to produce an error message:
177 fun.qml: Get back to work, slacker!
182 Without this, a generic "Game is not a type" message would be given.
184 #include <QtDeclarative> to use this function.
186 \sa qmlRegisterUncreatableType()
190 \fn int qmlRegisterType()
191 \relates QDeclarativeEngine
194 This template function registers the C++ type in the QML
195 system. Instances of this type cannot be created from the QML
198 #include <QtDeclarative> to use this function.
200 Returns the QML type id.
204 \fn int qmlRegisterInterface(const char *typeName)
205 \relates QDeclarativeEngine
207 This template function registers the C++ type in the QML system
208 under the name \a typeName.
210 #include <QtDeclarative> to use this function.
212 Returns the QML type id.