aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/src/qmllanguageref/documents/definetypes.qdoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/doc/src/qmllanguageref/documents/definetypes.qdoc')
-rw-r--r--src/qml/doc/src/qmllanguageref/documents/definetypes.qdoc56
1 files changed, 54 insertions, 2 deletions
diff --git a/src/qml/doc/src/qmllanguageref/documents/definetypes.qdoc b/src/qml/doc/src/qmllanguageref/documents/definetypes.qdoc
index d0faf04a04..dde54e2af6 100644
--- a/src/qml/doc/src/qmllanguageref/documents/definetypes.qdoc
+++ b/src/qml/doc/src/qmllanguageref/documents/definetypes.qdoc
@@ -319,17 +319,69 @@ the file, no matter how deeply nested.
With this pragma you can change the way type annotations on functions are
handled. By default the interpreter and JIT ignore type annotations, but
-\l{qmlcachegen} and \l{qmlsc} enforce them when compiling to C++.
+the \l{QML Script Compiler} enforces them when compiling to C++.
Specifying \c{Enforce} as value makes sure the type annotations are always
enforced. The resulting type coercions increase the overhead of calling
typed JavaScript functions.
-Specifying \c{Ignore} as value makes \l{qmlsc} and \l{qmlcachegen} ignore
+Specifying \c{Ignore} as value makes the \l{QML Script Compiler} ignore
any JavaScript functions when compiling the document to C++. This means less
code is compiled to C++ ahead of time, and more code has to be interpreted or
JIT-compiled.
\sa {Type annotations and assertions}
+\section2 ValueTypeBehavior
+
+The behavior of \l{QML Value Types} and list types differs slightly
+depending on whether a QML document is compiled to C++ using the
+\l{QML Script Compiler} or interpreted at run time.
+
+With this pragma you can change the way value types and sequences are handled
+when retrieved as locals from properties. By default, the interpreter and JIT
+treat all value types and sequences as references. This means, if you change
+the local value, the original property is also changed. Furthermore, if you
+write the original property explicitly, the local value is also updated.
+
+When compiled to C++ using the \l{QML Script Compiler}, the local value is not
+updated when the property is written, and the property is only updated when
+written directly, without retrieving it as local value before.
+
+For example, the following code prints "1 1" when compiled to C++ and "5 5"
+when interpreted or JIT-compiled:
+
+\qml
+import QtQml
+
+QtObject {
+ id: root
+
+ property rect r: ({x: 1, y: 2, width: 3, height: 4})
+ property list<double> numbers: [1, 2, 3, 4, 5]
+
+ function manipulate() {
+ root.r = {x: 5, y: 6, width: 7, height: 8};
+ root.numbers = [5, 4, 3, 2, 1];
+ }
+
+ Component.onCompleted: {
+ var numbers = root.numbers;
+ var r = root.r;
+ manipulate()
+ console.log(r.x, numbers[0]);
+ }
+}
+\endqml
+
+You may notice that the behavior when interpreted or JIT-compiled can be rather
+confusing.
+
+Specifying \c{Copy} as value to the pragma makes the interpreter and JIT behave
+like the generated C++ code. This is the recommended way to handle the problem.
+Specifying \c{Reference} makes the \l{QML Script Compiler} skip any functions
+that use value types or sequences when generating C++ code. Those functions are
+then left to be interpreted or JIT-compiled with the default behavior of the
+interpreter and JIT.
+
*/