/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** 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_END_LICENSE$
**
****************************************************************************/
\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.
+ It is equivalent to a regular JavaScript variable, except that you
+ cannot assign a JavaScript function to such a property.
For example, var properties can store numbers, strings, objects and
arrays:
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 anArray: [1, 2, 3, "four", "five", (function() { return "six"; })]
property var anObject: { "foo": 10, "bar": 20 }
}
\endqml
+ Attempting to assign a JavaScript function to a var property will result in
+ a binding assignment as per other property types. You can assign a JavaScript
+ array containing a single function element instead.
+
It is important to note that changes in regular properties of JavaScript
objects assigned to a var property will \bold{not} trigger updates of bindings
that access them. The example below will display "The car has 4 wheels" as
}
\endqml
+ A \c var type property can also hold an image or pixmap.
+ A \c var which contains a QPixmap or QImage is known as a
+ "scarce resource" and the declarative engine will attempt to
+ automatically release such resources after evaluation of any JavaScript
+ expression which requires one to be copied has completed.
+
+ Clients may explicitly release such a scarce resource by calling the
+ "destroy" method on the \c var property from within JavaScript. They
+ may also explicitly preserve the scarce resource by calling the
+ "preserve" method on the \c var property from within JavaScript.
+ For more information regarding the usage of a scarce resource, please
+ see \l{Scarce Resources in JavaScript}.
+
\sa {QML Basic Types}
*/