Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-updates > by-pkgid > 6e2327ca1c896c6d674ae53117299f21 > files > 138

qtdeclarative5-doc-5.12.6-1.mga7.noarch.rpm

<?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.12.6</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtqml-index.html">Qt QML</a></td><td ><a href="qtqml-qmlmodule.html">QML Types</a></td><td >var QML Basic Type</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtqml-index.html">Qt 5.12.6 Reference Documentation</a></td>
        </tr></table>
      </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">



</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 &quot;The car has 4 wheels&quot; as the change to the wheels property will not cause the reevaluation of the binding assigned to the &quot;text&quot; property:</p>
<pre class="qml">



</pre>
<p>If the onCompleted handler instead had <code>&quot;car = new Object({wheels: 6})&quot;</code> then the text would be updated to say &quot;The car has 6 wheels&quot;, 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">



</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 (&quot;{}&quot;), 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">



</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">&copy;</acronym> 2019 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>