aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/src/typesystem/topic.qdoc
blob: 3fe17943bb152c5a517ff27598b616a70f479efd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** GNU Free Documentation License
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms
** and conditions contained in a signed written agreement between you
** and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\page qtqml-typesystem-topic.html
\title The QML Type System
\brief Description of the QML type system

The types which may be used in the definition of an object hierarchy in a QML
document can come from various sources.  They may be:

\list
\li provided natively by the QML language
\li registered via C++ by QML modules
\li provided as QML documents by QML modules
\endlist

Furthermore, application developers can provide their own types, either by
registering C++ types directly, or by defining reusable components in QML
documents which can then be imported.

Wherever the type definitions come from, the engine will enforce type-safety
for properties and instances of those types.


\section1 Basic Types

The QML language has built-in support for various primitive types including
integers, double-precision floating point numbers, strings, and boolean values.
Objects may have properties of these types, and values of these types may be
passed as arguments to methods of objects.

See the \l{qtqml-typesystem-basictypes.html}{QML Basic Types} documentation for
more information about basic types.

\section1 JavaScript Types

JavaScript objects and arrays are supported by the QML engine. Any standard
JavaScript type can be created and stored using the generic \l var type.

For example, the standard \c Date and \c Array types are available, as below:

\qml
import QtQuick 2.0

Item {
    property var theArray: new Array()
    property var theDate: new Date()

    Component.onCompleted: {
        for (var i = 0; i < 10; i++)
            theArray.push("Item " + i)
        console.log("There are", theArray.length, "items in the array")
        console.log("The time is", theDate.toUTCString())
    }
}
\endqml

See \l {qtqml-javascript-expressions.html}{JavaScript Expressions in QML Documents} for more details.


\section1 QML Object Types

A QML object type is a type from which a QML object can be instantiated. QML
object types are derived from \l QtObject, and are provided by QML modules.
Applications can import these modules to use the object types they provide.
The \c QtQuick module provides the most common object types needed to create
user interfaces in QML.

Finally, every QML document implicitly defines a QML object type, which can be
re-used in other QML documents.  See the documentation about
\l{qtqml-typesystem-objecttypes.html}{object types in the QML type system} for
in-depth information about object types.

\section1 Property Modifier Types

A property modifier type is a special kind of QML object type.  A property
modifier type instance affects a property (of a QML object instance) which it
is applied to.  There are two different kinds of property modifier types:
\list
\li property value write interceptors
\li property value sources
\endlist

A property value write interceptor can be used to filter or modify values as
they are written to properties.  Currently, the only supported property
value write interceptor is the \l Behavior type provided by the \c QtQuick
import.

A property value source can be used to automatically update the value of a
property over time.  Clients can define their own property value source types.
The various \l{qtquick-statesanimations-animations.html}{property animation}
types provided by the \c QtQuick import are examples of property value
sources.

Property modifier type instances can be created and applied to a property of
a QML object through the "<ModifierType> on <propertyName>" syntax, as the
following example shows:

\qml
import QtQuick 2.0

Item {
    width: 400
    height: 50

    Rectangle {
        width: 50
        height: 50
        color: "red"

        NumberAnimation on x {
            from: 0
            to: 350
            loops: Animation.Infinite
            duration: 2000
        }
    }
}
\endqml

See the documentation on \l QQmlPropertyValueSource for information about how
to define your own property value source types.

*/