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
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
12void cppQmlInterface(QObject *qmlObject)
13{
15 QGeoAddress geoAddress = qmlObject->property("address").value<QGeoAddress>();
17
19 qmlObject->setProperty("address", QVariant::fromValue(geoAddress));
21
23 QGeoLocation geoLocation = qmlObject->property("location").value<QGeoLocation>();
25
27 qmlObject->setProperty("location", QVariant::fromValue(geoLocation));
29}
30
31class MyClass : public QObject
32{
35public:
37 {
39 if (monitor) {
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
56public Q_SLOTS:
58 {
59 Q_UNUSED(mon);
60
61 qDebug() << "Now within 100 meters, current position is" << update.coordinate();
62 }
63
65 {
66 Q_UNUSED(mon);
67
68 qDebug() << "No longer within 100 meters, current position is" << update.coordinate();
69 }
71};
void areaEntered(const QGeoAreaMonitorInfo &mon, const QGeoPositionInfo &update)
Definition cppqml.cpp:57
void areaExited(const QGeoAreaMonitorInfo &mon, const QGeoPositionInfo &update)
Definition cppqml.cpp:64
MyClass()
[BigBen]
Definition cppqml.cpp:36
\inmodule QtPositioning
Definition qgeoaddress.h:18
\inmodule QtPositioning
\inmodule QtPositioning
static QGeoAreaMonitorSource * createDefaultSource(QObject *parent)
Creates and returns a monitor source with the given parent that monitors areas using resources on the...
virtual bool startMonitoring(const QGeoAreaMonitorInfo &monitor)=0
Returns true if the monitoring of monitor could be successfully started; otherwise returns false.
\inmodule QtPositioning
Definition qgeocircle.h:15
\inmodule QtPositioning
\inmodule QtPositioning
\inmodule QtPositioning
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
QVariant property(const char *name) const
Returns the value of the object's name property.
Definition qobject.cpp:4323
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
T value() const &
Definition qvariant.h:516
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:536
void update()
Updates the widget unless updates are disabled or the widget is hidden.
#define qDebug
[1]
Definition qlogging.h:164
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
void cppQmlInterface(QObject *qmlObject)
Definition cppqml.cpp:15
#define Q_OBJECT
#define Q_SLOTS
#define Q_UNUSED(x)