このページでは

C++とQML間のインターフェース(コード内)Qt Positioning

概要

Qt Positioning では、C++とQMLコード間の位置データのやり取りを簡略化するために、2つの手法を採用しています。

直接マッピング

Qt Positioning これにより、以下の値型をQMLからC++へ、またその逆に渡すことが可能になります:

QVariant に基づく統合

このセクションでは、QGeoAddress およびQGeoLocation を統合する方法について説明します。

住所 - QGeoAddress

Address.address プロパティは、C++コードとQMLコード間のインターフェースとして使用されます。まず、C++側からAddress オブジェクトへのポインタを取得し、次にproperty()およびsetProperty()関数を使用して、address プロパティの取得および設定を行う必要があります。

以下のコードは、C++側からQGeoAddress オブジェクトを取得するものです:

 QGeoAddress geoAddress = qmlObject->property("address").value<QGeoAddress>();

以下のコードは、C++ からの `QGeoAddress ` オブジェクトに基づいて、QML オブジェクトの `address` プロパティを設定するものです:

qmlObject->setProperty("address", QVariant::fromValue(geoAddress));

Location - QGeoLocation

Location.location プロパティは、C++とQMLコード間のインターフェースを提供するために使用されます。まず、C++側からLocation オブジェクトへのポインタを取得し、次に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.