Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cppqml.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
#
include
<
QtCore
/
QObject
>
5
#
include
<
QtCore
/
QDebug
>
6
#
include
<
QtCore
/
QVariant
>
7
#
include
<
QtPositioning
/
QGeoAddress
>
8
#
include
<
QtPositioning
/
QGeoLocation
>
9
#
include
<
QtPositioning
/
QGeoCircle
>
10
#
include
<
QtPositioning
/
QGeoAreaMonitorSource
>
11
12
void
cppQmlInterface
(QObject *qmlObject)
13
{
14
//! [Address get]
15
QGeoAddress geoAddress = qmlObject->property(
"address"
).value<QGeoAddress>();
16
//! [Address get]
17
18
//! [Address set]
19
qmlObject->setProperty(
"address"
, QVariant::fromValue(geoAddress));
20
//! [Address set]
21
22
//! [Location get]
23
QGeoLocation geoLocation = qmlObject->property(
"location"
).value<QGeoLocation>();
24
//! [Location get]
25
26
//! [Location set]
27
qmlObject->setProperty(
"location"
, QVariant::fromValue(geoLocation));
28
//! [Location set]
29
}
30
31
class
MyClass
:
public
QObject
32
{
33
Q_OBJECT
34
//! [BigBen]
35
public
:
36
MyClass
() :
QObject
()
37
{
38
QGeoAreaMonitorSource
*
monitor
=
QGeoAreaMonitorSource
::
createDefaultSource
(
this
);
39
if
(
monitor
) {
40
connect
(
monitor
,
SIGNAL
(
areaEntered
(
QGeoAreaMonitorInfo
,
QGeoPositionInfo
)),
41
this
,
SLOT
(
areaEntered
(
QGeoAreaMonitorInfo
,
QGeoPositionInfo
)));
42
connect
(
monitor
,
SIGNAL
(
areaExited
(
QGeoAreaMonitorInfo
,
QGeoPositionInfo
)),
43
this
,
SLOT
(
areaExited
(
QGeoAreaMonitorInfo
,
QGeoPositionInfo
)));
44
45
QGeoAreaMonitorInfo
bigBen
(
"Big Ben"
);
46
QGeoCoordinate
position
(51.50104, -0.124632);
47
bigBen
.
setArea
(
QGeoCircle
(
position
, 100));
48
49
monitor
->
startMonitoring
(
bigBen
);
50
51
}
else
{
52
qDebug
() <<
"Could not create default area monitor"
;
53
}
54
}
55
56
public
Q_SLOTS
:
57
void
areaEntered
(
const
QGeoAreaMonitorInfo
&
mon
,
const
QGeoPositionInfo
&
update
)
58
{
59
Q_UNUSED
(
mon
);
60
61
qDebug
() <<
"Now within 100 meters, current position is"
<<
update
.
coordinate
();
62
}
63
64
void
areaExited
(
const
QGeoAreaMonitorInfo
&
mon
,
const
QGeoPositionInfo
&
update
)
65
{
66
Q_UNUSED
(
mon
);
67
68
qDebug
() <<
"No longer within 100 meters, current position is"
<<
update
.
coordinate
();
69
}
70
//! [BigBen]
71
};
MyClass
[5]
Definition
doc_src_properties.cpp:68
cppQmlInterface
void cppQmlInterface(QObject *qmlObject)
Definition
cppqml.cpp:15
qtpositioning
src
positioning
doc
snippets
cpp
cppqml.cpp
Generated on
for Qt by
1.18.0