Improve QtQml module documentation
[profile/ivi/qtdeclarative.git] / src / qml / doc / src / typesystem / basictypes.qdoc
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
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
13 ** this file.
14 **
15 ** Other Usage
16 ** Alternatively, this file may be used in accordance with the terms
17 ** and conditions contained in a signed written agreement between you
18 ** and Nokia.
19 **
20 **
21 **
22 **
23 **
24 ** $QT_END_LICENSE$
25 **
26 ****************************************************************************/
27 /*!
28 \page qtqml-typesystem-basictypes.html
29 \title QML Basic Types
30 \brief Description of basic types provided by the Qt QML module
31
32 QML supports a number of basic types.
33
34 A \e{basic type} is one that refers to a simple value, such as an \c int
35 or a \c string. This contrasts with a \l{qtqml-typesystem-topic.html#qml-object-types}{QML Object Types},
36 which refers to an object with properties, signals, methods and so on. Unlike an object type,
37 a basic type cannot be used to declare QML objects: it is not possible, for example, to declare an
38 \c int{} object or a \c size{} object.
39
40 Basic types can be used to refer to:
41
42 \list
43 \li A single value (e.g. \l int refers to a single number, \l var can refer to a single list of items)
44 \li A value that contains a simple set of property-value pairs (e.g. \l size refers to a value with \c width and \c height attributes)
45 \endlist
46
47 \sa {qtqml-typesystem-topic.html}{The QML Type System}
48
49
50 \section1 Supported Basic Types
51
52 Most basic types are supported by the engine by default and do not require an
53 \l {Import Statements}{Import Statement} to be used, unlike QML object types.
54 Some basic types which contain multiple property-value pairs (also known as \c{value types})
55 do require an import, as they are provided by the QtQuick module.
56 The basic types supported in QML are listed below:
57
58 \annotatedlist qmlbasictypes
59
60
61 \section1 Property Change Behavior for Basic Types
62
63 Some basic types have properties: for example, the \l font type has
64 \c pixelSize, \c family and \c bold properties. Unlike properties of
65 \l{qtqml-typesystem-topic.html#qml-object-types}{object types}, properties of
66 basic types do not provide their own property change signals. It is only possible
67 to create a property change signal handler for the basic type property itself:
68
69 \code
70 Text {
71     // invalid!
72     onFont.pixelSizeChanged: doSomething()
73
74     // also invalid!
75     font {
76         onPixelSizeChanged: doSomething()
77     }
78
79     // but this is ok
80     onFontChanged: doSomething()
81 }
82 \endcode
83
84 Be aware, however, that a property change signal for a basic type is emitted
85 whenever \e any of its attributes have changed, as well as when the property itself
86 changes. Take the following code, for example:
87
88 \qml
89 Text {
90     onFontChanged: console.log("font changed")
91
92     Text { id: otherText }
93
94     focus: true
95
96     // changing any of the font attributes, or reassigning the property
97     // to a different font value, will invoke the onFontChanged handler
98     Keys.onDigit1Pressed: font.pixelSize += 1
99     Keys.onDigit2Pressed: font.bold = !font.bold
100     Keys.onDigit3Pressed: font = otherText.font
101 }
102 \endqml
103
104 In contrast, properties of an \l{qtqml-typesystem-topic.html#qml-object-types}{object type}
105 emit their own property change signals, and a property change signal handler for an object-type
106 property is only invoked when the property is reassigned to a different object value.
107
108 */
109
110 /*!
111     \qmlbasictype int
112     \ingroup qmlbasictypes
113     \brief a whole number, e.g. 0, 10, or -20.
114
115     The \c int type refers to a whole number, e.g. 0, 10, or -20.
116
117     The possible \c int values range from around -2000000000 to around 2000000000,
118     although most elements will only accept a reduced range (which they
119     mention in their documentation).
120
121     Example:
122     \qml
123     Item { width: 100; height: 200 }
124     \endqml
125
126     This basic type is provided by the QML language.
127
128     \sa {QML Basic Types}
129 */
130
131 /*!
132     \qmlbasictype bool
133     \ingroup qmlbasictypes
134     \brief a binary true/false value.
135
136     The \c bool type refers to a binary true/false value.
137
138     Example:
139     \qml
140     Item {
141         focus: true
142         clip: false
143     }
144     \endqml
145
146     This basic type is provided by the QML language.
147
148     \sa {QML Basic Types}
149 */
150
151 /*!
152     \qmlbasictype real
153     \ingroup qmlbasictypes
154
155     \brief a number with a decimal point.
156
157     The \c real type refers to a number with decimal point, e.g. 1.2 or -29.8.
158
159     Example:
160     \qml
161     Item { width: 100.45; height: 150.82 }
162     \endqml
163
164     \b{Note:} In QML all reals are stored in double precision, \l
165     {http://en.wikipedia.org/wiki/IEEE_754} {IEEE floating point}
166     format.
167
168     This basic type is provided by the QML language.
169
170     \sa {QML Basic Types}
171 */
172
173 /*!
174     \qmlbasictype double
175     \ingroup qmlbasictypes
176
177     \brief a number with a decimal point, stored in double precision.
178
179     The \c double type refers to a number with a decimal point and is stored in double precision, \l
180     {http://en.wikipedia.org/wiki/IEEE_754} {IEEE floating point} format.
181
182     Example:
183     \qml
184     Item {
185         property double number: 32155.2355
186     }
187     \endqml
188
189     This basic type is provided by the QML language.
190
191     \sa {QML Basic Types}
192 */
193
194 /*!
195     \qmlbasictype string
196     \ingroup qmlbasictypes
197     \brief a free form text string.
198
199     The \c string type refers to a free form text string in quotes, e.g. "Hello world!".
200
201     Example:
202     \qml
203     Text { text: "Hello world!" }
204     \endqml
205
206     Strings have a \c length attribute that holds the number of
207     characters in the string.
208
209     QML extends the JavaScript String type with a \l {String::arg}{arg()} function
210     to support value substitution.
211
212     When integrating with C++, note that any QString value
213     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
214     converted into a \c string value, and vice-versa.
215
216     This basic type is provided by the QML language.
217
218     \sa {QML Basic Types}
219 */
220
221 /*!
222     \qmlbasictype url
223     \ingroup qmlbasictypes
224     \brief a resource locator.
225
226     The \c url type refers to a resource locator (like a file name, for example). It can be either
227     absolute, e.g. "http://qt.nokia.com", or relative, e.g.  "pics/logo.png". A relative URL is
228     resolved relative to the URL of the containing component.
229
230     For example, the following assigns a valid URL to the \l {Image::source}
231     property, which is of type \c url:
232
233     \qml
234     Image { source: "pics/logo.png" }
235     \endqml
236
237     When integrating with C++, note that any QUrl value
238     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
239     converted into a \c url value, and vice-versa.
240
241
242     \section1 Using the url type
243
244     When a relative URL is written to a \c url type property, it is converted
245     into a URL object, so \bold {matching the URL value against the input string
246     value will fail}. Instead, convert the string to a URL using Qt.resolvedUrl()
247     for means of comparison, and use \c toString() to get the contents of the URL:
248
249     \qml
250     Image {
251         source: "pics/logo.png"
252
253         Component.onCompleted: {
254             // This prints 'false'. Although "pics/logo.png" was the input string,
255             // it's been converted from a string to a URL, so these two are not the same.
256             console.log(source == "pics/logo.png")
257
258             // This prints 'true' as Qt.resovledUrl() converts the string into a
259             // URL with the correctly resolved path
260             console.log(source == Qt.resolvedUrl("pics/logo.png"))
261
262             // This prints the absolute path, e.g. "file:///path/to/pics/logo.png"
263             console.log(source.toString())
264         }
265     }
266     \endqml
267
268     \note When referring to files stored with the \l{resources.html}{Qt Resource System}
269     from within QML, you should use "qrc:///" instead of ":/" as QML requires URL paths.
270     Relative URLs resolved from within that file will use the same protocol.
271
272     Additionally, URLs may contain encoded characters using the 'percent-encoding' scheme
273     specified by \l {http://tools.ietf.org/html/rfc3986}{RFC 3986}.  These characters
274     will be preserved within properties of type \c url, to allow QML code to
275     construct precise URL values. An exception to this rule is the preemptive
276     decoding of directory-separator characters (\c '/') - these characters are decoded
277     to allow the URL to be correctly classified.
278
279     For example, a local file containing a '#' character, which would normally be
280     interpreted as the beginning of the URL 'fragment' element, can be accessed by
281     encoding the characters of the file name:
282
283     \qml
284     Image { source: encodeURIComponent("/tmp/test#1.png") }
285     \endqml
286
287     This basic type is provided by the QML language.
288
289     \sa {QML Basic Types}
290 */
291
292 /*!
293     \qmlbasictype color
294     \ingroup qmlbasictypes
295     \brief an ARGB color value.
296     \target qmlbasictypecolor
297
298     The \c color type refers to an ARGB color value. It can be specified in a number of ways:
299
300     \list
301     \li By a \l{http://www.w3.org/TR/SVG/types.html#ColorKeywords}{SVG color name}, such as
302         "red", "green" or "lightsteelblue".
303     \li By a hexadecimal triplet or quad in the form \c "#RRGGBB" and \c "#AARRGGBB"
304         respectively. For example, the color red corresponds to a triplet of \c "#FF0000"
305         and a slightly transparent blue to a quad of \c "#800000FF".
306     \li Using the \l{QML:Qt::rgba()}{Qt.rgba()}, \l{QML:Qt::hsla()}{Qt.hsla()},
307         \l{QML:Qt::darker()}{Qt.darker()}, \l{QML:Qt::lighter()}{Qt.lighter()} or
308         \l{QML:Qt::tint()}{Qt.tint()} functions.
309     \endlist
310
311     Example:
312
313     \div{float-right}
314     \inlineimage declarative-colors.png
315     \enddiv
316     \snippet qml/colors.qml colors
317
318     Additionally, a color type has \c r, \c g, \c b and \c a properties that refer to the
319     red, green, blue and alpha values of the color, respectively:
320
321     \qml
322     Text {
323         color: "red"
324
325         // prints "1 0 0 1"
326         Component.onCompleted: console.log(color.r, color.g, color.b, color.a)
327     }
328     \endqml
329
330     To test color values for equality, use the \l{QML:Qt::colorEqual()}{Qt.colorEqual()}
331     function.  This allows colors to be accurately compared whether they are in property
332     form or in any of the acceptable string specification forms.
333
334     When integrating with C++, note that any QColor value
335     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
336     converted into a \c color value, and vice-versa.
337
338     This basic type is provided by the QtQuick import.
339
340     \sa {QML Basic Types}
341 */
342
343 /*!
344     \qmlbasictype point
345     \ingroup qmlbasictypes
346     \brief a value with x and y attributes.
347
348     The \c point type refers to a value with \c x and \c y attributes.
349
350     To create a \c point value, specify it as a "x,y" string:
351
352     \qml
353     CustomObject { myPointProperty: "0,20" }
354     \endqml
355
356     Or use the \l{QML:Qt::point()}{Qt.point()} function:
357
358     \qml
359     CustomObject { myPointProperty: Qt.point(0, 20) }
360     \endqml
361
362     When integrating with C++, note that any QPoint or QPointF value
363     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
364     converted into a \c point value. When a \c point value is passed to C++, it
365     is automatically converted into a QPointF value.
366
367     This basic type is provided by the QML language.
368
369     \sa {QML Basic Types}
370 */
371
372 /*!
373     \qmlbasictype size
374     \ingroup qmlbasictypes
375     \brief a value with width and height attributes
376
377     The \c size type refers to a value with has \c width and \c height attributes.
378
379     For example, to read the \c width and \c height values of the
380     \l {Image::sourceSize} size-type property:
381
382     \qml
383     Column {
384         Image { id: image; source: "logo.png" }
385         Text { text: image.sourceSize.width + "," + image.sourceSize.height }
386     }
387     \endqml
388
389     To create a \c size value, specify it as a "width x height" string:
390
391     \qml
392     Image { sourceSize: "150x50" }
393     \endqml
394
395     Or use the \l{QML:Qt::size()}{Qt.size()} function:
396
397     \qml
398     Image { sourceSize: Qt.size(150, 50) }
399     \endqml
400
401     When integrating with C++, note that any QSize or QSizeF value
402     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
403     converted into a \c size value, and vice-versa. When a \c size value is passed to C++, it
404     is automatically converted into a QSizeF value.
405
406     This basic type is provided by the QML language.
407
408     \sa {QML Basic Types}
409 */
410
411 /*!
412     \qmlbasictype rect
413     \ingroup qmlbasictypes
414     \brief a value with x, y, width and height attributes.
415
416     The \c rect type refers to a value with \c x, \c y, \c width and \c height attributes.
417
418     For example, to read the \c width and \c height values of the \l Item
419     \l {Item::}{childrenRect} rect-type type property:
420
421     \qml
422     Rectangle {
423         width: childrenRect.width
424         height: childrenRect.height
425
426         Rectangle { width: 100; height: 100 }
427     }
428     \endqml
429
430     To create a \c rect value, specify it as a "x, y, width x height" string:
431
432     \qml
433     CustomObject { myRectProperty: "50,50,100x100" }
434     \endqml
435
436     Or use the \l{QML:Qt::rect()}{Qt.rect()} function:
437
438     \qml
439     CustomObject { myRectProperty: Qt.rect(50, 50, 100, 100) }
440     \endqml
441
442     When integrating with C++, note that any QRect or QRectF value
443     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
444     converted into a \c rect value, and vice-versa. When a \c rect value is passed to C++, it
445     is automatically converted into a QRectF value.
446
447     This basic type is provided by the QML language.
448
449     \sa {QML Basic Types}
450 */
451
452 /*!
453     \qmlbasictype date
454     \ingroup qmlbasictypes
455     \brief a date value.
456
457     The \c date type refers to a date value.
458
459     To create a \c date value, specify it as a "YYYY-MM-DD" string:
460
461     \qml
462     MyDatePicker { minDate: "2000-01-01"; maxDate: "2020-12-31" }
463     \endqml
464
465     To read a date value returned from a C++ extension class, use
466     \l{QML:Qt::formatDate()}{Qt.formatDate()} and \l{QML:Qt::formatDateTime()}{Qt.formatDateTime()}.
467
468     When integrating with C++, note that any QDate value
469     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
470     converted into a \c date value, and vice-versa.
471
472     Note that the date type has comparison semantics which match
473     those of the JavaScript Date object.  To compare the value
474     of two date properties, you should compare their "toString()"
475     values.
476
477     This basic type is provided by the QML language.
478
479     \sa {QML Basic Types}
480 */
481
482 /*!
483     \qmlbasictype time
484     \ingroup qmlbasictypes
485     \brief a time value.
486
487     The \c time type refers to a time value.
488
489     To create a \c time value, specified as "hh:mm:ss":
490
491     \qml
492     MyTimePicker { time: "14:22:15" }
493     \endqml
494
495     To read a time value returned from a C++ extension class, use
496     \l{QML:Qt::formatTime()}{Qt.formatTime()} and \l{QML:Qt::formatDateTime()}{Qt.formatDateTime()}.
497
498     Note that when converting historical times to and from javascript that QDateTime and the JS Date object
499     have different methods of calculating historical daylight savings time application. This can lead to variations of one hour
500     when converting to historical local time.
501
502     When integrating with C++, note that any QTime value
503     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
504     converted into a \c time value, and vice-versa.
505
506     This basic type is provided by the QML language.
507
508     \sa {QML Basic Types}
509  */
510
511 /*!
512     \qmlbasictype font
513     \ingroup qmlbasictypes
514     \brief a font value with the properties of QFont.
515     \target fontbasictypedocs
516
517     The \c font type refers to a font value with the properties of QFont.
518
519     The most commonly used properties are:
520
521     \list
522     \li \l string \c font.family
523     \li \l bool \c font.bold
524     \li \l bool \c font.italic
525     \li \l bool \c font.underline
526     \li \l real \c font.pointSize
527     \li \l int \c font.pixelSize
528     \endlist
529
530     If both \c pointSize and a \c pixelSize are specified, \c pixelSize will be used.
531
532     The following properties are also available:
533
534     \list
535     \li \l enumeration \c font.weight
536     \li \l bool \c font.overline
537     \li \l bool \c font.sstrikeout
538     \li \l enumeration \c font.capitalization
539     \li \l real \c font.letterSpacing
540     \li \l real \c font.wordSpacing
541     \endlist
542
543     Example:
544     \qml
545     Text { font.family: "Helvetica"; font.pointSize: 13; font.bold: true }
546     \endqml
547
548     When integrating with C++, note that any QFont value
549     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
550     converted into a \c font value, and vice-versa.
551
552     This basic type is provided by the QtQuick import.
553
554     Font weighting is classified on a scale from 0 to 99, where a weight of 0 is ultralight,
555     and 99 is extremely black. The following values are supported:
556
557     \table
558     \row
559         \li \c Font.Light
560         \li 25
561     \row
562         \li \c Font.Normal
563         \li 50
564     \row
565         \li \c Font.DemiBold
566         \li 63
567     \row
568         \li \c Font.Bold
569         \li 75
570     \row
571         \li \c Font.Black
572         \li 87
573     \endtable
574
575     Capitalization supports the following values:
576
577     \table
578     \row
579         \li \c Font.MixedCase
580         \li No capitalization change is applied.
581     \row
582         \li \c Font.AllUppercase
583         \li Alters the text to be rendered in all uppercase type.
584     \row
585         \li \c Font.AllLowercase
586         \li Alters the text to be rendered in all lowercase type.
587     \row
588         \li \c Font.SmallCaps
589         \li Alters the text to be rendered in small-caps type.
590     \row
591         \li \c Font.Capitalize
592         \li Alters the text to be rendered with the first character of each word as an uppercase character.
593     \endtable
594
595     \sa {QML Basic Types}
596 */
597
598 /*!
599     \qmlbasictype list
600     \ingroup qmlbasictypes
601     \brief a list of QML objects.
602
603     The \c list type refers to a list of QML objects.
604
605     A list value can be accessed in a similar way to a JavaScript array:
606
607     \list
608     \li Values are assigned using the \c[] square bracket syntax with comma-separated values
609     \li The \c length property provides the number of items in the list
610     \li Values in the list are accessed using the \c [index] syntax
611     \endlist
612
613     A \c list can only store QML objects, and cannot contain any
614     \l {QML Basic Types}{basic type} values. (To store basic types within a
615     list, use the \l var type instead.)
616
617     When integrating with C++, note that any QQmlListProperty value
618     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
619     converted into a \c list value, and vice-versa.
620
621
622     \section1 Using the list type
623
624     For example, the \l Item type has a \l {Item::}{states} list-type property that
625     can be assigned to and used as follows:
626
627     \qml
628     import QtQuick 2.0
629
630     Item {
631         width: 100; height: 100
632
633         states: [
634             State { name: "activated" },
635             State { name: "deactivated" }
636         ]
637
638         Component.onCompleted: {
639             console.log("Name of first state:", states[0].name)
640             for (var i=0; i<states.length; i++)
641                 console.log("state", i, states[i].name)
642         }
643     }
644     \endqml
645
646     The defined \l State objects will be added to the \c states list
647     in the order in which they are defined.
648
649     If the list only contains one object, the square brackets may be omitted:
650
651     \qml
652     import QtQuick 2.0
653
654     Item {
655         width: 100; height: 100
656         states: State { name: "activated" }
657     }
658     \endqml
659
660     Note that objects cannot be individually added to or removed from
661     the list once created; to modify the contents of a list, it must be
662     reassigned to a new list.
663
664     \note The \c list type is not recommended as a type for custom properties.
665     The \c var type should be used instead for this purpose as
666     lists stored by the \c var type can be manipulated with greater
667     flexibility from within QML.
668
669     This basic type is provided by the QML language.
670
671     \sa {QML Basic Types}
672 */
673
674  /*!
675     \qmlbasictype var
676     \ingroup qmlbasictypes
677     \brief a generic property type.
678
679     The \c var type is a generic property type that can refer to any data type.
680
681     It is equivalent to a regular JavaScript variable.
682     For example, var properties can store numbers, strings, objects,
683     arrays and functions:
684
685     \qml
686     Item {
687         property var aNumber: 100
688         property var aBool: false
689         property var aString: "Hello world!"
690         property var anotherString: String("#FF008800")
691         property var aColor: Qt.rgba(0.2, 0.3, 0.4, 0.5)
692         property var aRect: Qt.rect(10, 10, 10, 10)
693         property var aPoint: Qt.point(10, 10)
694         property var aSize: Qt.size(10, 10)
695         property var aVector3d: Qt.vector3d(100, 100, 100)
696         property var anArray: [1, 2, 3, "four", "five", (function() { return "six"; })]
697         property var anObject: { "foo": 10, "bar": 20 }
698         property var aFunction: (function() { return "one"; })
699     }
700     \endqml
701
702     \section1 Change Notification Semantics
703
704     It is important to note that changes in regular properties of JavaScript
705     objects assigned to a var property will \b{not} trigger updates of bindings
706     that access them.  The example below will display "The car has 4 wheels" as
707     the change to the wheels property will not cause the reevaluation of the
708     binding assigned to the "text" property:
709
710     \qml
711     Item {
712         property var car: new Object({wheels: 4})
713
714         Text {
715             text: "The car has " + car.wheels + " wheels";
716         }
717
718         Component.onCompleted: {
719             car.wheels = 6;
720         }
721     }
722     \endqml
723
724     If the onCompleted handler instead had \tt{"car = new Object({wheels: 6})"}
725     then the text would be updated to say "The car has 6 wheels", since the
726     car property itself would be changed, which causes a change notification
727     to be emitted.
728
729     \section1 Property Value Initialization Semantics
730
731     The QML syntax defines that curly braces on the right-hand-side of a
732     property value initialization assignment denote a binding assignment.
733     This can be confusing when initializing a \c var property, as empty curly
734     braces in JavaScript can denote either an expression block or an empty
735     object declaration.  If you wish to initialize a \c var property to an
736     empty object value, you should wrap the curly braces in parentheses.
737
738     For example:
739     \qml
740     Item {
741         property var first:  {}   // nothing = undefined
742         property var second: {{}} // empty expression block = undefined
743         property var third:  ({}) // empty object
744     }
745     \endqml
746
747     In the previous example, the \c first property is bound to an empty
748     expression, whose result is undefined.  The \c second property is bound to
749     an expression which contains a single, empty expression block ("{}"), which
750     similarly has an undefined result.  The \c third property is bound to an
751     expression which is evaluated as an empty object declaration, and thus the
752     property will be initialized with that empty object value.
753
754     Similarly, a colon in JavaScript can be either an object property value
755     assignment, or a code label.  Thus, initializing a var property with an
756     object declaration can also require parentheses:
757
758     \qml
759     Item {
760         property var first: { example: 'true' }    // example is interpreted as a label
761         property var second: ({ example: 'true' }) // example is interpreted as a property
762         property var third: { 'example': 'true' }  // example is interpreted as a property
763         Component.onCompleted: {
764             console.log(first.example) // prints 'undefined', as "first" was assigned a string
765             console.log(second.example) // prints 'true'
766             console.log(third.example) // prints 'true'
767         }
768     }
769     \endqml
770
771     \section1 Using Scarce Resources with the var Type
772
773     A \c var type property can also hold an image or pixmap.
774     A \c var which contains a QPixmap or QImage is known as a
775     "scarce resource" and the declarative engine will attempt to
776     automatically release such resources after evaluation of any JavaScript
777     expression which requires one to be copied has completed.
778
779     Clients may explicitly release such a scarce resource by calling the
780     "destroy" method on the \c var property from within JavaScript.  They
781     may also explicitly preserve the scarce resource by calling the
782     "preserve" method on the \c var property from within JavaScript.
783     For more information regarding the usage of a scarce resource, please
784     see \l{Scarce Resources in JavaScript}.
785
786     This basic type is provided by the QML language.
787
788     \sa {QML Basic Types}
789 */
790
791
792 /*!
793     \obsolete
794     \qmlbasictype variant
795     \ingroup qmlbasictypes
796     \brief a generic property type.
797
798     The \c variant type is a generic property type. It is obsolete and exists only to
799     support old applications; new applications should use \l var type
800     properties instead.
801
802     A variant type property can hold any of the \l {QML Basic Types}{basic type}
803     values:
804
805     \qml
806     Item {
807         property variant aNumber: 100
808         property variant aString: "Hello world!"
809         property variant aBool: false
810     }
811     \endqml
812
813     When integrating with C++, note that any QVariant value
814     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
815     converted into a \c variant value, and vice-versa.
816
817
818     \section1 Using Scarce Resources with the variant Type
819
820     A \c variant type property can also hold an image or pixmap.
821     A \c variant which contains a QPixmap or QImage is known as a
822     "scarce resource" and the declarative engine will attempt to
823     automatically release such resources after evaluation of any JavaScript
824     expression which requires one to be copied has completed.
825
826     Clients may explicitly release such a scarce resource by calling the
827     "destroy" method on the \c variant property from within JavaScript.  They
828     may also explicitly preserve the scarce resource by calling the
829     "preserve" method on the \c variant property from within JavaScript.
830     For more information regarding the usage of a scarce resource, please
831     see \l{Scarce Resources in JavaScript}.
832
833     \section1 Storing Arrays and Objects
834
835     The \c variant type can also hold:
836
837     \list
838     \li An array of \l {QML Basic Types}{basic type} values
839     \li A map of key-value pairs with \l {QML Basic Types}{basic-type} values
840     \endlist
841
842     For example, below is an \c items array and an \c attributes map. Their
843     contents can be examined using JavaScript \c for loops. Individual array
844     values are accessible by index, and individual map values are accessible
845     by key:
846
847     \qml
848     Item {
849         property variant items: [1, 2, 3, "four", "five"]
850         property variant attributes: { 'color': 'red', 'width': 100 }
851
852         Component.onCompleted: {
853             for (var i=0; i<items.length; i++)
854                 console.log(items[i])
855
856             for (var prop in attributes)
857                 console.log(prop, "=", attributes[prop])
858         }
859     }
860     \endqml
861
862     While this is a convenient way to store array and map-type values, you
863     must be aware that the \c items and \c attributes properties above are \e not
864     QML objects (and certainly not JavaScript object either) and the key-value
865     pairs in \c attributes are \e not QML properties. Rather, the \c items
866     property holds an array of values, and \c attributes holds a set of key-value
867     pairs. Since they are stored as a set of values, instead of as an object,
868     their contents \e cannot be modified individually:
869
870     \qml
871     Item {
872         property variant items: [1, 2, 3, "four", "five"]
873         property variant attributes: { 'color': 'red', 'width': 100 }
874
875         Component.onCompleted: {
876             items[0] = 10
877             console.log(items[0])     // This will still be '1'!
878             attributes.color = 'blue'
879             console.log(attributes.color)     // This will still be 'red'!
880         }
881     }
882     \endqml
883
884     Since it is not possible to individually add or remove items from a list or
885     object stored in a \c variant, the only way to modify its contents is to
886     reassign a new value. However, this is not efficent, as it causes the value
887     to be serialized and deserialized.
888
889     Additionally, since \c items and \c attributes are not QML objects, changing
890     their individual values do not trigger property change notifications. If
891     the above example had \c onNumberChanged or \c onAnimalChanged signal
892     handlers, they would not have been called.  If, however, the \c items or
893     \c attributes properties themselves were reassigned to different values, then
894     such handlers would be called.
895
896     JavaScript programmers should also note that when a JavaScript object is
897     copied to an array or map property, the \e contents of the object (that is,
898     its key-value properties) are copied, rather than the object itself. The
899     property does not hold a reference to the original JavaScript object, and
900     extra data such as the object's JavaScript prototype chain is also lost in
901     the process.
902
903     This basic type is provided by the QML language.
904
905     \sa {QML Basic Types}
906 */
907
908 /*!
909     \qmlbasictype vector2d
910     \ingroup qmlbasictypes
911
912     \brief A vector2d type has x and y attributes.
913
914     A \c vector2d type has \c x and \c y attributes, otherwise
915     it is similar to the \c vector3d type.  Please see the
916     documentation about the \c vector3d type for more information.
917
918     To create a \c vector2d value, specify it as a "x,y" string,
919     or define the components individually, or compose it with
920     the Qt.vector2d() function.
921
922     This basic type is provided by the QtQuick import.
923
924     \sa {QML Basic Types}
925 */
926
927 /*!
928     \qmlbasictype vector3d
929     \ingroup qmlbasictypes
930     \brief a value with x, y, and z attributes.
931
932     The \c vector3d type refers to a value with \c x, \c y, and \c z attributes.
933
934     To create a \c vector3d value, specify it as a "x,y,z" string:
935
936     \qml
937     Rotation { angle: 60; axis: "0,1,0" }
938     \endqml
939
940     or with the \l{QML:Qt::vector3d()}{Qt.vector3d()} function:
941
942     \qml
943     Rotation { angle: 60; axis: Qt.vector3d(0, 1, 0) }
944     \endqml
945
946     or as separate \c x, \c y, and \c z components:
947
948     \qml
949     Rotation { angle: 60; axis.x: 0; axis.y: 1; axis.z: 0 }
950     \endqml
951
952     When integrating with C++, note that any QVector3D value
953     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
954     converted into a \c vector3d value, and vice-versa.
955
956     This basic type is provided by the QtQuick import.
957
958     \sa {QML Basic Types}
959 */
960
961 /*!
962     \qmlbasictype vector4d
963     \ingroup qmlbasictypes
964
965     \brief A vector4d type has x, y, z and w attributes.
966
967     A \c vector4d type has \c x, \c y, \c z and \c w attributes,
968     otherwise it is similar to the \c vector3d type.  Please see the
969     documentation about the \c vector3d type for more information.
970
971     To create a \c vector4d value, specify it as a "x,y,z,w" string,
972     or define the components individually, or compose it with
973     the Qt.vector4d() function.
974
975     This basic type is provided by the QtQuick import.
976
977     \sa {QML Basic Types}
978 */
979
980 /*!
981     \qmlbasictype quaternion
982     \ingroup qmlbasictypes
983
984     \brief A quaternion type has scalar, x, y, and z attributes.
985
986     A \c quaternion type has \c scalar, \c x, \c y and \c z attributes,
987     otherwise it is similar to the \c vector3d type.  Please see the
988     documentation about the \c vector3d type for more information.
989
990     To create a \c quaternion value, specify it as a "scalar,x,y,z" string,
991     or define the components individually, or compose it with
992     the Qt.quaternion() function.
993
994     This basic type is provided by the QtQuick import.
995
996     \sa {QML Basic Types}
997 */
998
999 /*!
1000     \qmlbasictype matrix4x4
1001     \ingroup qmlbasictypes
1002
1003     \brief A matrix4x4 type is a 4-row and 4-column matrix
1004
1005     A \c matrix4x4 type has sixteen values, but these values are
1006     largely opaque to QML.  Values of this type can be composed with
1007     the Qt.matrix4x4() function.
1008
1009     This basic type is provided by the QtQuick import.
1010
1011     \sa {QML Basic Types}
1012 */
1013
1014 /*!
1015     \qmlbasictype enumeration
1016     \ingroup qmlbasictypes
1017     \brief a set of named values.
1018
1019     The \c enumeration type refers to a set of named values.
1020
1021     Each named value can be referred to as \c {<Type>.<value>}. For
1022     example, the \l Text type has an \c AlignRight enumeration value:
1023
1024     \qml
1025     Text { horizontalAlignment: Text.AlignRight }
1026     \endqml
1027
1028     (For backwards compatibility, the enumeration value may also be
1029     specified as a string, e.g. "AlignRight". This form is not
1030     recommended for new code.)
1031
1032     When integrating with C++, note that any enumeration value
1033     \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
1034     converted into an \c enumeration value, and vice-versa.
1035
1036     This basic type is provided by the QML language.  Some enumeration values
1037     are provided by the QtQuick import.
1038
1039     \sa {QML Basic Types}
1040 */
1041