Data Type Conversion Between QML and C++▲
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 in QML or C++. This requires the exchanged data to be of a type that is recognizable by the engine.
The QML engine provides built-in support for a large number of Qt C++ data types. Additionally, custom C++ types may be registered with the QML type system to make them available to the engine.
For more information about C++ and the different QML integration methods, see the C++ and QML integration overview page.
This page discusses the data types supported by the QML engine and how they are converted between QML and C++.
Data Ownership▲
When data is transferred from C++ to QML, the ownership of the data always remains with C++. The exception to this rule is when a QObject is returned from an explicit C++ method call: in this case, the QML engine assumes ownership of the object, unless the ownership of the object has explicitly been set to remain with C++ by invoking QQmlEngine::setObjectOwnership() with QQmlEngine::CppOwnership specified.
Additionally, the QML engine respects the normal QObject parent ownership semantics of Qt C++ objects, and will never delete a QObject instance which has a parent.
Basic Qt Data Types▲
By default, QML recognizes the following Qt data types, which are automatically converted to a corresponding QML basic type when passed from C++ to QML and vice-versa: