diff options
author | Chris Adams <christopher.adams@nokia.com> | 2011-09-30 11:14:10 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-06 05:29:00 +0200 |
commit | 752cd2aca42f6625f1cfc364937e0d39828cf954 (patch) | |
tree | dcb8891d7ff0d99d7bcbf948ed6339c4cce6b257 /doc/src/declarative | |
parent | 6bd1704c42f564980677682e1d47e91129d94e5c (diff) |
Add JavaScript "var" property type to QML
This commit adds a new syntax which allows "var" type properties
which can have JavaScript objects (as well as other basic types)
assigned to them. Such JavaScript objects cannot be bound to.
Task-number: QMLNG-18
Change-Id: If7f5045f4669e0d5c1b8d0891ed765128d0bc1c6
Reviewed-on: http://codereview.qt-project.org/1466
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'doc/src/declarative')
-rw-r--r-- | doc/src/declarative/basictypes.qdoc | 59 | ||||
-rw-r--r-- | doc/src/declarative/whatsnew.qdoc | 3 |
2 files changed, 60 insertions, 2 deletions
diff --git a/doc/src/declarative/basictypes.qdoc b/doc/src/declarative/basictypes.qdoc index 0133ab5efe..1bc13739fa 100644 --- a/doc/src/declarative/basictypes.qdoc +++ b/doc/src/declarative/basictypes.qdoc @@ -422,14 +422,69 @@ \sa {QML Basic Types} */ + /*! + \qmlbasictype var + \ingroup qmlbasictypes + + \brief A var type is a generic property type. + + A var is a generic property type capable of storing any data type. + It is equivalent to a regular JavaScript variable. + For example, var properties can store numbers, strings, objects and + arrays: + + \qml + Item { + property var aNumber: 100 + property var aBool: false + property var aString: "Hello world!" + property var anotherString: String("#FF008800") + property var aColor: Qt.rgba(0.2, 0.3, 0.4, 0.5) + property var aRect: Qt.rect(10, 10, 10, 10) + property var aPoint: Qt.point(10, 10) + property var aSize: Qt.size(10, 10) + property var aVector3d: Qt.vector3d(100, 100, 100) + property var anArray: [1, 2, 3, "four", "five"] + property var anObject: { "foo": 10, "bar": 20 } + } + \endqml + + It is important to note that properties of JavaScript objects cannot + be bound to: + + \qml + Item { + property var car: new vehicle(4) + property int wheelCount: car.wheels + + function vehicle(wheels) { + this.wheels = wheels; + this.talk = function() { print("I have " + this.wheels + " wheels!"); } + } + + Component.onCompleted: { + car.wheels = 6; // wheelCount will _not_ be updated + } + } + \endqml + + \sa {QML Basic Types} +*/ + + /*! + \obsolete \qmlbasictype variant \ingroup qmlbasictypes \brief A variant type is a generic property type. - A variant is a generic property type. A variant type property can hold - any of the \l {QML Basic Types}{basic type} values: + A variant is a generic property type. It is obsolete and exists only to + support old applications; new applications should use "var" type + properties instead. + + A variant type property can hold any of the \l {QML Basic Types}{basic type} + values: \qml Item { diff --git a/doc/src/declarative/whatsnew.qdoc b/doc/src/declarative/whatsnew.qdoc index a9a1ecb25f..4efe0da2ff 100644 --- a/doc/src/declarative/whatsnew.qdoc +++ b/doc/src/declarative/whatsnew.qdoc @@ -120,6 +120,9 @@ header and footer items). ListView section.labelPositioning property added to allow keeping the current section label at the start and/or next section label at the end of the view. +A new property type ("var") has been introduced which obsoletes "variant" properties in QML. +Properties of this type are equivalent to regular JavaScript variables. See the documentation +on \l{QML Basic Types} for more information about "var" properties. \section2 QtQuick 1 is now a separate library and module |