Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
cpp-qml-positioning.qdoc
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page positioning-cpp-qml.html
6\title Interfaces between C++ and QML Code in Qt Positioning
7
8\brief Describes the methods used to exchange position data between C++ and QML
9code.
10
11\section1 Overview
12
13Qt Positioning utilizes two methods to simplify exchange of position data
14between C++ and QML code.
15
16\target Cpp_value_integration_positioning
17\section1 Direct C++ Value Integration in QtPositioning
18
19Starting with Qt 5.5, it has become much easier to integrate non-QObject based
20data types into QML. This is achieved by adding \l Q_GADGET support to \l QtQml.
21The macro converts classes into a light-weight version of a \l QObject without
22the required \l QObject inheritance. At the same time, it retains the reflection
23capabilities of \l QMetaObject. As a result, they can be directly exposed to
24QML.
25
26A significant number of Position related data types were converted to
27\l {Q_GADGET}s. They retain their API and value type character but have become
28introspectable via \l QMetaObject.
29
30The \l QML_ANONYMOUS macro is used to expose these types to the QML environment.
31See the \l QQmlEngine documentation for more details and the full list of
32available macros.
33
34The classes, however, are not directly extended with this macro, because we do
35not want Qt Positioning to depend on \l QtQml. So a helper class is created for
36each of them, and the \l QML_FOREIGN macro is used:
37
38\code
39struct QGeoCoordinateForeign
40{
41 Q_GADGET
42 QML_FOREIGN(QGeoCoordinate)
43 QML_ANONYMOUS
44 QML_ADDED_IN_VERSION(5, 0)
45};
46\endcode
47
48The above registration of Positioning types is automatically done once by the
49QtPositioning QML plugin.
50
51\section1 QVariant Based integration
52
53This section provides information on how to integrate QGeoAddress and
54QGeoLocation.
55
56\section2 Address - QGeoAddress
57
58The \l {QtPositioning::Address::address} {Address.address} property is used to
59provide an interface between C++ and QML code. First a pointer to an
60\l {QtPositioning::}{Address} object must be obtained from C++, then the
61\l {QObject::}{property()} and \l {QObject::}{setProperty()} functions must be
62used to get and set the \c address property.
63
64The following piece of code gets the \l QGeoAddress object from C++:
65
66\snippet cpp/cppqml.cpp Address get
67
68The following piece of code sets the address property of the QML object based
69on a \l QGeoAddress object from C++:
70
71\snippet cpp/cppqml.cpp Address set
72
73
74\section2 Location - QGeoLocation
75The \l {Location::location} {Location.location} property is used to provide an
76interface between C++ and QML code. First a pointer to a \l Location object
77must be obtained from C++, then the \l {QObject::}{property()} and
78\l {QObject::}{setProperty()} functions must be used to get and set the
79\c location property.
80
81The following piece of code gets the \l QGeoLocation object from C++:
82
83\snippet cpp/cppqml.cpp Location get
84
85The following piece of code sets the location property of the QML object based
86on a \l QGeoLocation object from C++:
87
88\snippet cpp/cppqml.cpp Location set
89
90*/