Sophie

Sophie

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

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" />
<!-- objecttypes.qdoc -->
  <title>QML Object Types | 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 >QML Object Types</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="#defining-object-types-from-qml">Defining Object Types from QML</a></li>
<li class="level2"><a href="#defining-object-types-through-qml-documents">Defining Object Types Through QML Documents</a></li>
<li class="level2"><a href="#defining-anonymous-types-with-component">Defining Anonymous Types with Component</a></li>
<li class="level1"><a href="#defining-object-types-from-c">Defining Object Types from C++</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QML Object Types</h1>
<span class="subtitle"></span>
<!-- $$$qtqml-typesystem-objecttypes.html-description -->
<div class="descr"> <a name="details"></a>
<p>A QML object type is a type from which a QML object can be instantiated.</p>
<p>In syntactic terms, a QML object type is one which can be used to declare an object by specifying the <i>type name</i> followed by a set of curly braces that encompasses the attributes of that object. This differs from <i>basic types</i>, which cannot be used in the same way. For example, Rectangle is a QML object type: it can be used to create <code>Rectangle</code> type objects. This cannot be done with primitive types such as <code>int</code> and <code>bool</code>, which are used to hold simple data types rather than objects.</p>
<p>Custom QML object types can be defined by creating a .qml file that defines the type, as discussed in <a href="qtqml-documents-definetypes.html">Documents as QML object type definitions</a>, or by defining a QML type from C++ and registering the type with the QML engine, as discussed in <a href="qtqml-cppintegration-definetypes.html">Defining QML Types from C++</a>. Note that in both cases, the type name must begin with an uppercase letter in order to be declared as a QML object type in a QML file.</p>
<a name="defining-object-types-from-qml"></a>
<h2 id="defining-object-types-from-qml">Defining Object Types from QML</h2>
<a name="defining-object-types-through-qml-documents"></a>
<h3 id="defining-object-types-through-qml-documents">Defining Object Types Through QML Documents</h3>
<p>Plugin writers and application developers may provide types defined as QML documents. A QML document, when visible to the QML import system, defines a type identified by the name of the file minus the file extensions.</p>
<p>Thus, if a QML document named &quot;MyButton.qml&quot; exists, it provides the definition of the &quot;MyButton&quot; type, which may be used in a QML application.</p>
<p>See the documentation about <a href="qtqml-documents-topic.html">QML Documents</a> for information on how to define a QML document, and the syntax of the QML language. Once you are familiar with the QML language and how to define QML documents, see the documentation which explains how to <a href="qtqml-documents-definetypes.html">define and use your own reusable QML types in QML documents</a>.</p>
<p>See <a href="qtqml-documents-definetypes.html">Defining Object Types through QML Documents</a> for more information.</p>
<a name="defining-anonymous-types-with-component"></a>
<h3 id="defining-anonymous-types-with-component">Defining Anonymous Types with Component</h3>
<p>Another method of creating object types from within QML is to use the <a href="qml-qtqml-component.html">Component</a> type. This allows a type to be defined inline within a QML document, instead of using a separate document in a <code>.qml</code> file.</p>
<pre class="qml">



</pre>
<p>Here the <code>myComponent</code> object essentially defines an anonymous type that can be instantiated using <a href="qml-qtqml-component.html#createObject-method">Component::createObject</a> to create objects of this anonymous type.</p>
<p>Inline components share all the characteristics of regular top-level components and use the same <code>import</code> list as their containing QML document.</p>
<p>Note that each <a href="qml-qtqml-component.html">Component</a> object declaration creates its own <i>component scope</i>. Any <i>id</i> values used and referred to from within a <a href="qml-qtqml-component.html">Component</a> object declaration must be unique within that scope, but do not need to be unique within the document within which the inline component is declared. So, the Rectangle declared in the <code>myComponent</code> object declaration could have an <i>id</i> of <code>root</code> without conflicting with the <code>root</code> declared for the Item object in the same document, as these two <i>id</i> values are declared within different component scopes.</p>
<p>See <a href="qtqml-documents-scope.html">Scope and Naming Resolution</a> for more details.</p>
<a name="defining-object-types-from-c"></a>
<h2 id="defining-object-types-from-c">Defining Object Types from C++</h2>
<p>C++ plugin writers and application developers may register types defined in C++ through API provided by the Qt QML module. There are various registration functions which each allow different use-cases to be fulfilled. For more information about those registration functions, and the specifics of exposing custom C++ types to QML, see the documentation regarding <a href="qtqml-cppintegration-definetypes.html">Defining QML Types from C++</a>.</p>
<p>The QML type-system relies on imports, plugins and extensions being installed into a known import path. Plugins may be provided by third-party developers and reused by client application developers. Please see the documentation about <a href="qtqml-modules-topic.html">QML modules</a> for more information about how to create and deploy a QML extension module.</p>
</div>
<!-- @@@qtqml-typesystem-objecttypes.html -->
        </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>