Interfacce tra C++ e QML Codice in Qt Positioning
Panoramica
Qt Positioning utilizza due metodi per semplificare lo scambio di dati di posizione tra il codice C++ e quello QML.
Mappatura diretta
Qt Positioning consente di passare i seguenti tipi di valori da QML a C++ e viceversa:
| Classe C++ | Tipo di valore QML |
|---|---|
| QGeoCircle | geoCircle |
| QGeoCoordinate | geoCoordinate |
| QGeoPath | geoPath |
| QGeoPolygon | geoPolygon |
| QGeoRectangle | geoRectangle |
| QGeoSatelliteInfo | geoSatelliteInfo |
| QGeoShape | geoShape |
Integrazione basata su QVariant
Questa sezione fornisce informazioni su come integrare QGeoAddress e QGeoLocation.
Indirizzo - QGeoAddress
La proprietà Address.address viene utilizzata per fornire un'interfaccia tra il codice C++ e quello QML. Innanzitutto è necessario ottenere da C++ un puntatore a un oggetto Address, quindi occorre utilizzare le funzioni property() e setProperty() per ottenere e impostare la proprietà address.
Il seguente frammento di codice ottiene l’oggetto QGeoAddress dal C++:
QGeoAddress geoAddress = qmlObject->property("address").value<QGeoAddress>();Il seguente frammento di codice imposta la proprietà address dell’oggetto QML in base a un oggetto QGeoAddress proveniente da C++:
qmlObject->setProperty("address", QVariant::fromValue(geoAddress));Location - QGeoLocation
La proprietà ` Location.location ` viene utilizzata per fornire un'interfaccia tra il codice C++ e quello QML. Innanzitutto è necessario ottenere da C++ un puntatore a un oggetto ` Location `, quindi occorre utilizzare le funzioni ` property()` e ` setProperty()` per recuperare e impostare la proprietà ` location `.
Il seguente frammento di codice recupera l’oggetto QGeoLocation da C++:
QGeoLocation geoLocation = qmlObject->property("location").value<QGeoLocation>();Il seguente frammento di codice imposta la proprietà `location` dell’oggetto QML in base a un oggetto ` QGeoLocation ` proveniente da C++:
qmlObject->setProperty("location", QVariant::fromValue(geoLocation));© 2026 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.