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
routehandler.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
5class RouteHandler : public QObject
6{
8public:
10 const QGeoCoordinate &origin,
12
14
15 // The request defaults to the fastest route by car, which is
16 // equivalent to:
17 // request.setTravelMode(QGeoRouteRequest::CarTravel);
18 // request.setRouteOptimization(QGeoRouteRequest::FastestRoute);
19
20 request.setAvoidFeatureTypes(QGeoRouteRequest::AvoidTolls);
21 request.setAvoidFeatureTypes(QGeoRouteRequest::AvoidMotorPoolLanes);
22
23 QGeoRouteRequest::AvoidFeaturesTypes avoidableFeatures = routingManager->supportedAvoidFeatureTypes();
24
25 if (!(avoidableFeatures & request.avoidFeatureTypes())) {
26 // ... inform the user that the routing manager does not
27 // provide support for avoiding tolls and/or motor pool lanes ...
28 return;
29 }
30
31 QGeoRouteReply *reply = routingManager->calculateRoute(request);
32
33 if (reply->isFinished()) {
35 routeCalculated(reply);
36 } else {
37 routeError(reply, reply->error(), reply->errorString());
38 }
39 return;
40 }
41
43 this, &RouteHandler::routeCalculated);
44
46 this, &RouteHandler::routeError);
47 }
48
49private slots:
50 void routeCalculated(QGeoRouteReply *reply)
51 {
52 // A route request can ask for several alternative routes ...
53 if (reply->routes().size() != 0) {
54
55 // ... but by default it will only get a single route
56 QGeoRoute route = reply->routes().at(0);
57
58 //... now we have to make use of the route ...
59 }
60
62 }
63
65 {
66 // ... inform the user that an error has occurred ...
68 }
69};
\inmodule QtPositioning
\inmodule QtLocation
\inmodule QtLocation
\inmodule QtLocation
Definition qgeoroute.h:24
\inmodule QtLocation
void finished(QGeoRouteReply *reply)
This signal is emitted when reply has finished processing.
void errorOccurred(QGeoRouteReply *reply, QGeoRouteReply::Error error, const QString &errorString=QString())
This signal is emitted when an error has been detected in the processing of reply.
QGeoRouteReply * calculateRoute(const QGeoRouteRequest &request)
Begins the calculation of the route specified by request.
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
bool isFinished() const
NetworkError error() const
Returns the error that was found during the processing of this request.
\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
void deleteLater()
\threadsafe
Definition qobject.cpp:2435
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
[RouteHandler]
Definition routehandler.h:6
RouteHandler(QGeoRoutingManager *routingManager, const QGeoCoordinate &origin, const QGeoCoordinate &destination)
Definition routehandler.h:9
Q_MULTIMEDIA_EXPORT QString errorString(HRESULT hr)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char * destination
DBusConnection const char DBusError * error
#define Q_OBJECT
#define slots
QNetworkRequest request(url)
QNetworkReply * reply