1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the documentation of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:FDL$
9 ** GNU Free Documentation License
10 ** Alternatively, this file may be used under the terms of the GNU Free
11 ** Documentation License version 1.3 as published by the Free Software
12 ** Foundation and appearing in the file included in the packaging of
16 ** Alternatively, this file may be used in accordance with the terms
17 ** and conditions contained in a signed written agreement between you
26 ****************************************************************************/
28 \page qtqml-typereference-topic.html
29 \title QML Types Provided By The QtQml Module
30 \brief List of QML types provided by the QtQml module
32 The \c QtQml module provides the definition and implementation of various
33 convenience types which can be used with the QML language, including some
34 elementary QML types which can provide the basis for further extensions to the
37 The \c QtQml module provides the \c QtObject and \c Component object types
38 which may be used in QML documents. These types are non-visual and provide
39 building-blocks for extensions to QML.
41 \section1 Importing QtQml
43 The types provided by the \c QtQml module are only available in a QML document
44 if that document imports the \c QtQml namespace (or if the document imports the
45 \c QtQuick namespace, as noted below).
47 The current version of the \c QtQml module is version 2.0, and thus it may be
48 imported via the following statement:
54 Most clients will never need to use the \c QtQml import, as all of the types
55 and functionality provided by the \c QtQml namespace are also provided by the
56 \c QtQuick namespace which may be imported as follows:
62 See the \l{QtQuick}{QtQuick} module documentation for more information about the
63 \c QtQuick namespace and what it provides to QML application developers.
65 The documentation for the types below applies equally to the types of the same
66 name provided by the \l{QtQuick}{QtQuick} module, as they are in fact identical.
70 The following \l{qtqml-typesystem-basictypes.html}{QML basic types} are
73 \annotatedlist qtqmlbasictypes
75 \section1 Object Types
77 The following \l{qtqml-typesystem-objecttypes.html}{QML object types} are
82 The \c QtObject type provides a basic instantiable object which can be used in
83 QML applications. It is non-visual, but may have properties, methods, signals
86 For example, the following QtObject has several properties, one of which has
87 been assigned a \l{Property Binding}
88 {binding}, and a \l{Signal and Handler Event System}{signal handler} for
89 the default change signal which exists for one of its properties:
96 property int b: a + 22
97 property int changeCount: 0
107 The \c Component type provides a basic re-usable component which allows
108 instances of another type to be instantiated on-demand. It may be given an
109 \c id and it has a default property which is the object type to instantiate,
110 but no other properties may be added to it.
112 For example, the following QtObject has two different \l Component
113 properties, and it uses those components to dynamically construct objects at
121 property bool which: true
123 property Component a: Component {
126 property int answer: 42
127 function activate() {
128 console.log("The answer is: " + answer);
133 property Component b: Component {
136 property string message: "Hello, World!"
137 function activate() {
138 console.log(message);
143 function activateDynamicObject() {
147 o = a.createObject(null); // no parent
150 o = b.createObject(null); // no parent
161 \ingroup qtqmlbasictypes
162 \ingroup qtquickbasictypes
165 The \c date type refers to a date value.
167 To create a \c date value, specify it as a "YYYY-MM-DD" string:
170 MyDatePicker { minDate: "2000-01-01"; maxDate: "2020-12-31" }
173 To read a date value returned from a C++ extension class, use
174 \l{QML:Qt::formatDate()}{Qt.formatDate()} and \l{QML:Qt::formatDateTime()}{Qt.formatDateTime()}.
176 When integrating with C++, note that any QDate value
177 \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
178 converted into a \c date value, and vice-versa.
180 Note that the date type has comparison semantics which match
181 those of the JavaScript Date object. To compare the value
182 of two date properties, you should compare their "toString()"
185 This basic type is provided by the QML language.
187 \sa {QML Basic Types}
192 \ingroup qtqmlbasictypes
193 \ingroup qtquickbasictypes
196 The \c time type refers to a time value.
198 To create a \c time value, specified as "hh:mm:ss":
201 MyTimePicker { time: "14:22:15" }
204 To read a time value returned from a C++ extension class, use
205 \l{QML:Qt::formatTime()}{Qt.formatTime()} and \l{QML:Qt::formatDateTime()}{Qt.formatDateTime()}.
207 Note that when converting historical times to and from javascript that QDateTime and the JS Date object
208 have different methods of calculating historical daylight savings time application. This can lead to variations of one hour
209 when converting to historical local time.
211 When integrating with C++, note that any QTime value
212 \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
213 converted into a \c time value, and vice-versa.
215 This basic type is provided by the QML language.
217 \sa {QML Basic Types}
222 \ingroup qtqmlbasictypes
223 \ingroup qtquickbasictypes
224 \brief a value with x and y attributes.
226 The \c point type refers to a value with \c x and \c y attributes.
228 To create a \c point value, specify it as a "x,y" string:
231 CustomObject { myPointProperty: "0,20" }
234 Or use the \l{QML:Qt::point()}{Qt.point()} function:
237 CustomObject { myPointProperty: Qt.point(0, 20) }
240 When integrating with C++, note that any QPoint or QPointF value
241 \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
242 converted into a \c point value. When a \c point value is passed to C++, it
243 is automatically converted into a QPointF value.
250 \ingroup qtqmlbasictypes
251 \ingroup qtquickbasictypes
252 \brief a value with width and height attributes
254 The \c size type refers to a value with has \c width and \c height attributes.
256 For example, to read the \c width and \c height values of the
257 \l {Image::sourceSize} size-type property:
261 Image { id: image; source: "logo.png" }
262 Text { text: image.sourceSize.width + "," + image.sourceSize.height }
266 To create a \c size value, specify it as a "width x height" string:
269 Image { sourceSize: "150x50" }
272 Or use the \l{QML:Qt::size()}{Qt.size()} function:
275 Image { sourceSize: Qt.size(150, 50) }
278 When integrating with C++, note that any QSize or QSizeF value
279 \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
280 converted into a \c size value, and vice-versa. When a \c size value is passed to C++, it
281 is automatically converted into a QSizeF value.
288 \ingroup qtqmlbasictypes
289 \ingroup qtquickbasictypes
290 \brief a value with x, y, width and height attributes.
292 The \c rect type refers to a value with \c x, \c y, \c width and \c height attributes.
294 For example, to read the \c width and \c height values of the \l Item
295 \l {Item::childrenRect.x}{childrenRect} rect-type type property:
299 width: childrenRect.width
300 height: childrenRect.height
302 Rectangle { width: 100; height: 100 }
306 To create a \c rect value, specify it as a "x, y, width x height" string:
309 CustomObject { myRectProperty: "50,50,100x100" }
312 Or use the \l{QML:Qt::rect()}{Qt.rect()} function:
315 CustomObject { myRectProperty: Qt.rect(50, 50, 100, 100) }
318 When integrating with C++, note that any QRect or QRectF value
319 \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
320 converted into a \c rect value, and vice-versa. When a \c rect value is passed to C++, it
321 is automatically converted into a QRectF value.