/usr/share/qt5/doc/qtqml/qtqml-cppintegration-overview.html is in qtdeclarative5-doc-html 5.9.5-0ubuntu1.
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 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- topic.qdoc -->
<title>Overview - QML and C++ Integration | Qt QML 5.9</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.9</td><td ><a href="qtqml-index.html">Qt QML</a></td><td >Overview - QML and C++ Integration</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.5 Reference Documentation</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="#exposing-attributes-of-c-classes-to-qml">Exposing Attributes of C++ Classes to QML</a></li>
<li class="level1"><a href="#defining-qml-types-from-c">Defining QML Types from C++</a></li>
<li class="level1"><a href="#embedding-c-objects-into-qml-with-context-properties">Embedding C++ Objects into QML with Context Properties</a></li>
<li class="level1"><a href="#interacting-with-qml-objects-from-c">Interacting with QML Objects from C++</a></li>
<li class="level1"><a href="#data-type-conversion-between-qml-and-c">Data Type Conversion Between QML and C++</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Overview - QML and C++ Integration</h1>
<span class="subtitle"></span>
<!-- $$$qtqml-cppintegration-overview.html-description -->
<div class="descr"> <a name="details"></a>
<p>QML is designed to be easily extensible through C++ code. The classes in the <a href="qtqml-index.html">Qt QML</a> module enable QML objects to be loaded and manipulated from C++, and the nature of QML engine's integration with Qt's <a href="../qtcore/metaobjects.html">meta object system</a> enables C++ functionality to be invoked directly from QML. This allows the development of hybrid applications which are implemented with a mixture of QML, JavaScript and C++ code.</p>
<p>Integrating QML and C++ provides a variety of opportunities, including the ability to:</p>
<ul>
<li>Separate the user interface code from the application logic code, by implementing the former with QML and JavaScript within <a href="qtqml-documents-topic.html">QML documents</a>, and the latter with C++</li>
<li>Use and invoke some C++ functionality from QML (for example, to invoke your application logic, use a data model implemented in C++, or call some functions in a third-party C++ library)</li>
<li>Access functionality in the <a href="qtqml-index.html">Qt QML</a> or Qt Quick C++ API (for example, to dynamically generate images using QQuickImageProvider)</li>
<li>Implement your own <a href="qtqml-typesystem-objecttypes.html">QML object types</a> from C++ — whether for use within your own specific application, or for distribution to others</li>
</ul>
<p>To provide some C++ data or functionality to QML, it must be made available from a <a href="../qtcore/qobject.html">QObject</a>-derived class. Due to the QML engine's integration with the meta object system, the properties, methods and signals of any <a href="../qtcore/qobject.html">QObject</a>-derived class are accessible from QML, as described in <a href="qtqml-cppintegration-exposecppattributes.html">Exposing Attributes of C++ Types to QML</a>. Once the required functionality is provided by such a class, it can be exposed to QML in a variety of ways:</p>
<ul>
<li>The class can be <a href="qtqml-cppintegration-definetypes.html#registering-an-instantiable-object-type"> registered as an instantiable QML type</a>, so that it can be instantiated and used like any ordinary <a href="qtqml-typesystem-objecttypes.html">QML object type</a> from QML code</li>
<li>The class can be registered as a <a href="qtqml-cppintegration-definetypes.html#registering-singleton-objects-with-a-singleton-type">Singleton Type</a> so that a single instance of the class may be imported from QML code, allowing the instance's properties, methods and signals to be accessed from QML</li>
<li>An instance of the class can be <a href="qtqml-cppintegration-contextproperties.html">embedded into QML code</a> as a <i>context property</i> or <i>context object</i>, allowing the instance's properties, methods and signals to be accessed from QML</li>
</ul>
<p>These are the most common methods of accessing C++ functionality from QML code; for more options and details, see the main documentation pages that are described in the sections further below. Additionally, aside from the ability to access C++ functionality from QML, the <a href="qtqml-index.html">Qt QML</a> module also provides ways to do the reverse and manipulate QML objects from C++ code. See <a href="qtqml-cppintegration-interactqmlfromcpp.html">Interacting with QML Objects from C++</a> for more details.</p>
<p>Finally, the C++ code may be integrated into either a C++ application or a C++ plugin depending on whether it is to be distributed as a standalone application or a library. A plugin can be integrated with a QML module that can then be imported and used by QML code in other applications; see <a href="qtqml-modules-cppplugins.html">Providing Types and Functionality in a C++ Plugin</a> for more information.</p>
<a name="exposing-attributes-of-c-classes-to-qml"></a>
<h2 id="exposing-attributes-of-c-classes-to-qml">Exposing Attributes of C++ Classes to QML</h2>
<p>QML can easily be extended from C++ due to the QML engine's integration with the Qt meta object system. This integration allows the properties, methods and signals of any <a href="../qtcore/qobject.html">QObject</a>-derived class to be accessible from QML: properties can be read and modified, methods can be invoked from JavaScript expressions and signal handlers are automatically created for signals as necessary. Additionally, enumeration values of a <a href="../qtcore/qobject.html">QObject</a>-derived class are accessible from QML.</p>
<p>See <a href="qtqml-cppintegration-exposecppattributes.html">Exposing Attributes of C++ Types to QML</a> for more information.</p>
<a name="defining-qml-types-from-c"></a>
<h2 id="defining-qml-types-from-c">Defining QML Types from C++</h2>
<p>QML types can be defined in C++ and then registered with the <a href="qtqml-typesystem-topic.html">QML type system</a>. This allows a C++ class to be instantiated as a <a href="qtqml-typesystem-objecttypes.html">QML object type</a>, enabling custom object types to be implemented in C++ and integrated into existing QML code. A C++ class may be also registered for other purposes: for example, it could be registered as a <i>Singleton Type</i> to enable a single class instance to be imported by QML code, or it could be registered to enable the enumeration values of a non-instantiable class to be accessible from QML.</p>
<p>Additionally, the <a href="qtqml-index.html">Qt QML</a> module provides mechanisms to define QML types that integrate with QML concepts like attached properties and default properties.</p>
<p>For more information on registering and creating custom QML types from C++, see the <a href="qtqml-cppintegration-definetypes.html">Defining QML Types from C++</a> documentation.</p>
<a name="embedding-c-objects-into-qml-with-context-properties"></a>
<h2 id="embedding-c-objects-into-qml-with-context-properties">Embedding C++ Objects into QML with Context Properties</h2>
<p>C++ objects and values can be embedded directly into the context (or <i>scope</i>) of loaded QML objects using <i>context properties</i> and <i>context objects</i>. This is achieved through the <a href="qqmlcontext.html">QQmlContext</a> class provided by the <a href="qtqml-index.html">Qt QML</a> module, which exposes data to the context of a QML component, allowing data to be injected from C++ into QML.</p>
<p>See <a href="qtqml-cppintegration-contextproperties.html">Embedding C++ Objects into QML with Context Properties</a> for more information.</p>
<a name="interacting-with-qml-objects-from-c"></a>
<h2 id="interacting-with-qml-objects-from-c">Interacting with QML Objects from C++</h2>
<p>QML object types can be instantiated from C++ and inspected in order to access their properties, invoke their methods and receive their signal notifications. This is possible due to the fact that all QML object types are implemented using <a href="../qtcore/qobject.html">QObject</a>-derived classes, enabling the QML engine to dynamically load and introspect objects through the Qt meta object system.</p>
<p>For more information on accessing QML objects from C++, see the documentation on <a href="qtqml-cppintegration-interactqmlfromcpp.html">Interacting with QML Objects from C++</a>.</p>
<a name="data-type-conversion-between-qml-and-c"></a>
<h2 id="data-type-conversion-between-qml-and-c">Data Type Conversion Between QML and C++</h2>
<p>When data values are exchanged between QML and C++, they are converted by the QML engine to have the correct data types as appropriate for use from QML or C++, providing the data types involved are known to the engine.</p>
<p>See <a href="qtqml-cppintegration-data.html">Data Type Conversion Between QML and C++</a> for information on the built-in types supported by the engine and how these types are converted for use when exchanged between QML and C++.</p>
</div>
<!-- @@@qtqml-cppintegration-overview.html -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2017 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>
|