/usr/share/qt5/doc/qtqml/qml-var.html is in qtdeclarative5-doc-html 5.5.1-2ubuntu6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- basictypes.qdoc -->
<title>var QML Basic Type | Qt QML 5.5</title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<ul>
<li>Qt 5.5</li>
<li><a href="qtqml-index.html">Qt QML</a></li>
<li><a href="qtqml-qmlmodule.html">QML Types</a></li>
<li>var QML Basic Type</li>
<li id="buildversion">Qt 5.5.1 Reference Documentation</li>
</ul>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#change-notification-semantics">Change Notification Semantics</a></li>
<li class="level1"><a href="#property-value-initialization-semantics">Property Value Initialization Semantics</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">var QML Basic Type</h1>
<span class="subtitle"></span>
<!-- $$$var-description -->
<div class="descr"> <a name="details"></a>
<p>a generic property type.</p>
<p>The <code>var</code> type is a generic property type that can refer to any data type.</p>
<p>It is equivalent to a regular JavaScript variable. For example, var properties can store numbers, strings, objects, arrays and functions:</p>
<pre class="qml"><span class="type">Item</span> {
property <span class="type">var</span> <span class="name">aNumber</span>: <span class="number">100</span>
property <span class="type">var</span> <span class="name">aBool</span>: <span class="number">false</span>
property <span class="type">var</span> <span class="name">aString</span>: <span class="string">"Hello world!"</span>
property <span class="type">var</span> <span class="name">anotherString</span>: <span class="name">String</span>(<span class="string">"#FF008800"</span>)
property <span class="type">var</span> <span class="name">aColor</span>: <span class="name">Qt</span>.<span class="name">rgba</span>(<span class="number">0.2</span>, <span class="number">0.3</span>, <span class="number">0.4</span>, <span class="number">0.5</span>)
property <span class="type">var</span> <span class="name">aRect</span>: <span class="name">Qt</span>.<span class="name">rect</span>(<span class="number">10</span>, <span class="number">10</span>, <span class="number">10</span>, <span class="number">10</span>)
property <span class="type">var</span> <span class="name">aPoint</span>: <span class="name">Qt</span>.<span class="name">point</span>(<span class="number">10</span>, <span class="number">10</span>)
property <span class="type">var</span> <span class="name">aSize</span>: <span class="name">Qt</span>.<span class="name">size</span>(<span class="number">10</span>, <span class="number">10</span>)
property <span class="type">var</span> <span class="name">aVector3d</span>: <span class="name">Qt</span>.<span class="name">vector3d</span>(<span class="number">100</span>, <span class="number">100</span>, <span class="number">100</span>)
property <span class="type">var</span> <span class="name">anArray</span>: [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="string">"four"</span>, <span class="string">"five"</span>, (<span class="keyword">function</span>() { <span class="keyword">return</span> <span class="string">"six"</span>; })]
property <span class="type">var</span> <span class="name">anObject</span>: { "foo": <span class="number">10</span>, "bar": <span class="number">20</span> }
property <span class="type">var</span> <span class="name">aFunction</span>: (<span class="keyword">function</span>() { <span class="keyword">return</span> <span class="string">"one"</span>; })
}</pre>
<a name="change-notification-semantics"></a>
<h2 id="change-notification-semantics">Change Notification Semantics</h2>
<p>It is important to note that changes in regular properties of JavaScript objects assigned to a var property will <b>not</b> trigger updates of bindings that access them. The example below will display "The car has 4 wheels" as the change to the wheels property will not cause the reevaluation of the binding assigned to the "text" property:</p>
<pre class="qml"><span class="type">Item</span> {
property <span class="type">var</span> <span class="name">car</span>: new <span class="name">Object</span>({wheels: <span class="number">4</span>})
<span class="type">Text</span> {
<span class="name">text</span>: <span class="string">"The car has "</span> <span class="operator">+</span> <span class="name">car</span>.<span class="name">wheels</span> <span class="operator">+</span> <span class="string">" wheels"</span>;
}
<span class="name">Component</span>.onCompleted: {
<span class="name">car</span>.<span class="name">wheels</span> <span class="operator">=</span> <span class="number">6</span>;
}
}</pre>
<p>If the onCompleted handler instead had <code>"car = new Object({wheels: 6})"</code> then the text would be updated to say "The car has 6 wheels", since the car property itself would be changed, which causes a change notification to be emitted.</p>
<a name="property-value-initialization-semantics"></a>
<h2 id="property-value-initialization-semantics">Property Value Initialization Semantics</h2>
<p>The QML syntax defines that curly braces on the right-hand-side of a property value initialization assignment denote a binding assignment. This can be confusing when initializing a <code>var</code> property, as empty curly braces in JavaScript can denote either an expression block or an empty object declaration. If you wish to initialize a <code>var</code> property to an empty object value, you should wrap the curly braces in parentheses.</p>
<p>For example:</p>
<pre class="qml"><span class="type">Item</span> {
property <span class="type">var</span> <span class="name">first</span>: {} <span class="comment">// nothing = undefined</span>
property <span class="type">var</span> <span class="name">second</span>: {{}} <span class="comment">// empty expression block = undefined</span>
property <span class="type">var</span> <span class="name">third</span>: ({}) <span class="comment">// empty object</span>
}</pre>
<p>In the previous example, the <code>first</code> property is bound to an empty expression, whose result is undefined. The <code>second</code> property is bound to an expression which contains a single, empty expression block ("{}"), which similarly has an undefined result. The <code>third</code> property is bound to an expression which is evaluated as an empty object declaration, and thus the property will be initialized with that empty object value.</p>
<p>Similarly, a colon in JavaScript can be either an object property value assignment, or a code label. Thus, initializing a var property with an object declaration can also require parentheses:</p>
<pre class="qml"><span class="type">Item</span> {
property <span class="type">var</span> <span class="name">first</span>: { <span class="name">example</span>: <span class="string">'true'</span> } <span class="comment">// example is interpreted as a label</span>
property <span class="type">var</span> <span class="name">second</span>: ({ example: <span class="string">'true'</span> }) <span class="comment">// example is interpreted as a property</span>
property <span class="type">var</span> <span class="name">third</span>: { 'example': <span class="string">'true'</span> } <span class="comment">// example is interpreted as a property</span>
<span class="name">Component</span>.onCompleted: {
<span class="name">console</span>.<span class="name">log</span>(<span class="name">first</span>.<span class="name">example</span>) <span class="comment">// prints 'undefined', as "first" was assigned a string</span>
<span class="name">console</span>.<span class="name">log</span>(<span class="name">second</span>.<span class="name">example</span>) <span class="comment">// prints 'true'</span>
<span class="name">console</span>.<span class="name">log</span>(<span class="name">third</span>.<span class="name">example</span>) <span class="comment">// prints 'true'</span>
}
}</pre>
</div>
<p><b>See also </b><a href="qtqml-typesystem-basictypes.html">QML Basic Types</a>.</p>
<!-- @@@var -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2015 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|