Interfaces between C++ and QML Code in Qt Positioning
Depending on the type of C++ class QtPositioning utilizes two methods to simplify exchange of position data between C++ and QML code.
Direct C++ Value Integration in QtPositioning
Starting with Qt 5.5, it has become much easier to integrate non-QObject based data types into QML. This is achieved by adding Q_GADGET support to QtQml. The macro converts classes into a light-weight version of a QObject without the required QObject inheritance. At the same time it retains the reflection capabilities of QMetaObject. As a result they can be directly exposed to QML and do not require any further wrapper classes.
A significant number of Position and Location related data types were converted to Q_GADGETs. They retain their API and value type character but have become introspectable via QMetaObject. This conversion was done to the following classes:
Using QGeoCoordinate as an example, the C++ types are directly exposed to the QML environment via its meta type:
QVariant Based integration
Address - QGeoAddress
The Address.address property is used to provide an interface between C++ and QML code. First a pointer to a Address object must be obtained from C++, then use the property() and setProperty() functions to get and set the
address property. The following gets the QGeoAddress representing this object from C++:
The following sets the properties of this object based on a QGeoAddress object from C++:
Location - QGeoLocation
The Location.location property is used to provide an interface between C++ and QML code. First a pointer to a Location object must be obtained from C++, then use the property() and setProperty() functions to get and set the
location property. The following gets the QGeoLocation representing this object from C++:
The following sets the properties of this object based on a QGeoLocation object from C++:
© 2017 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. 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.