C++とQMLコード間のインターフェイスQt Positioning
概要
Qt Positioning は、C++とQMLコード間の位置データ交換を簡単にするために、2つの方法を利用しています。
直接マッピング
Qt Positioning では、QMLからC++へ、あるいはC++からQMLへ、次のような値の型を渡すことができます:
| C++ クラス | QMLの値型 |
|---|---|
| QGeoCircle | geoCircle |
| QGeoCoordinate | geoCoordinate |
| QGeoPath | geoPath |
| QGeoPolygon | geoPolygon |
| QGeoRectangle | geoRectangle |
| QGeoSatelliteInfo | geoSatelliteInfo |
| QGeoShape | geoShape |
QVariant ベースの統合
このセクションでは、QGeoAddress とQGeoLocation の統合方法について説明します。
住所 - QGeoAddress
Address.address プロパティは、C++ と QML コード間のインターフェイスを提供するために使用され ます。まず、Address オブジェクトへのポインタを C++ から取得し、次にproperty() とsetProperty() 関数を用いてaddress プロパティを取得・設定する必要があります。
次のコードは C++ からQGeoAddress オブジェクトを取得するものです:
QGeoAddress geoAddress = qmlObject->property("address").value<QGeoAddress>();
次のコードは、C++からQGeoAddress オブジェクトを取得し、QML オブジェクトの Address プロパティを設定します:
qmlObject->setProperty("address", QVariant::fromValue(geoAddress));
場所 - QGeoLocation
Location.location プロパティは、C++ と QML のコード間のインターフェイスとして使用されます。まず、Location オブジェクトへのポインタを C++ から取得し、次にproperty() およびsetProperty() 関数を使ってlocation プロパティを取得・設定する必要があります。
次のコードは C++ からQGeoLocation オブジェクトを取得するものです:
QGeoLocation geoLocation = qmlObject->property("location").value<QGeoLocation>();
次のコードは、C++ からQGeoLocation オブジェクトを取得し、QML オブジェクトの location プロパティを設定します:
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.