C++와 QML 코드 간 인터페이스 Qt Positioning
개요
Qt Positioning 는 두 가지 방법을 사용하여 C++ 코드와 QML 코드 간의 위치 데이터 교환을 간소화합니다.
QtPositioning에서 직접 C++ 값 통합
Qt 5.5부터는QObject 기반이 아닌 데이터 유형을 QML에 통합하는 것이 훨씬 쉬워졌습니다. 이는 QtQml 에 Q_GADGET 지원을 추가함으로써 가능합니다. 이 매크로는 필요한 QObject 상속 없이 클래스를 QObject 의 경량 버전으로 변환합니다. 동시에 QMetaObject 의 리플렉션 기능도 유지하므로 QML에 직접 노출될 수 있습니다.
상당수의 Position 관련 데이터 유형이 Q_GADGETs로 변환되었습니다. 해당 API 및 값 유형 문자는 유지되지만 QMetaObject 을 통해 내재화할 수 있게 되었습니다.
QML_ANONYMOUS 매크로는 이러한 유형을 QML 환경에 노출하는 데 사용됩니다. 자세한 내용과 사용 가능한 매크로의 전체 목록은 QQmlEngine 문서를 참조하세요.
그러나 Qt Positioning 이 QtQml 에 종속되는 것을 원하지 않기 때문에 클래스는 이 매크로로 직접 확장되지 않습니다. 따라서 각각에 대해 헬퍼 클래스가 만들어지고 QML_FOREIGN 매크로가 사용됩니다:
struct QGeoCoordinateForeign { Q_GADGET QML_FOREIGN(QGeoCoordinate) QML_ANONYMOUS QML_ADDED_IN_VERSION(5, 0) };
위의 포지셔닝 유형 등록은 QtPositioning QML 플러그인에 의해 자동으로 한 번 수행됩니다.
Q배리언트 기반 통합
이 섹션에서는 QGeoAddress 과 QGeoLocation 을 통합하는 방법에 대한 정보를 제공합니다.
주소 - QGeoAddress
Address.address 속성은 C++ 코드와 QML 코드 간의 인터페이스를 제공하는 데 사용됩니다. 먼저 C++에서 Address 객체에 대한 포인터를 가져온 다음 property() 및 setProperty() 함수를 사용하여 address
속성을 가져오고 설정해야 합니다.
다음 코드는 C++에서 QGeoAddress 객체를 가져옵니다:
QGeoAddress geoAddress = qmlObject->property("address").value<QGeoAddress>();
다음 코드는 C++의 QGeoAddress 객체를 기반으로 QML 객체의 주소 속성을 설정합니다:
qmlObject->setProperty("address", QVariant::fromValue(geoAddress));
위치 - QGeoLocation
Location.location 속성은 C++ 코드와 QML 코드 간의 인터페이스를 제공하는 데 사용됩니다. 먼저 C++에서 Location 객체에 대한 포인터를 가져온 다음 property() 및 setProperty() 함수를 사용하여 location
속성을 가져오고 설정해야 합니다.
다음 코드는 C++에서 QGeoLocation 객체를 가져옵니다:
QGeoLocation geoLocation = qmlObject->property("location").value<QGeoLocation>();
다음 코드는 C++의 QGeoLocation 객체를 기반으로 QML 객체의 위치 속성을 설정합니다:
qmlObject->setProperty("location", QVariant::fromValue(geoLocation));
© 2025 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.