diff options
-rw-r--r-- | examples/positioning/weatherinfo/appmodel.cpp | 17 | ||||
-rw-r--r-- | examples/positioning/weatherinfo/appmodel.h | 3 |
2 files changed, 19 insertions, 1 deletions
diff --git a/examples/positioning/weatherinfo/appmodel.cpp b/examples/positioning/weatherinfo/appmodel.cpp index d0a37265..30d990d4 100644 --- a/examples/positioning/weatherinfo/appmodel.cpp +++ b/examples/positioning/weatherinfo/appmodel.cpp @@ -233,6 +233,8 @@ void AppModel::networkSessionOpened() d->useGps = true; connect(d->src, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo))); + connect(d->src, SIGNAL(error(QGeoPositionInfoSource::Error)), + this, SLOT(positionError(QGeoPositionInfoSource::Error))); d->src->startUpdates(); } else { d->useGps = false; @@ -277,6 +279,21 @@ void AppModel::positionUpdated(QGeoPositionInfo gpsPos) d->geoReplyMapper, SLOT(map())); } +void AppModel::positionError(QGeoPositionInfoSource::Error e) +{ + qWarning() << "Position source error. Falling back to simulation mode."; + // cleanup insufficient QGeoPositionInfoSource instance + d->src->stopUpdates(); + d->src->deleteLater(); + d->src = 0; + + // activate simulation mode + d->useGps = false; + d->city = "Brisbane"; + emit cityChanged(); + this->refreshWeather(); +} + void AppModel::handleGeoNetworkData(QObject *replyObj) { QNetworkReply *networkReply = qobject_cast<QNetworkReply*>(replyObj); diff --git a/examples/positioning/weatherinfo/appmodel.h b/examples/positioning/weatherinfo/appmodel.h index e0d32148..16297236 100644 --- a/examples/positioning/weatherinfo/appmodel.h +++ b/examples/positioning/weatherinfo/appmodel.h @@ -46,7 +46,7 @@ #include <QtNetwork/QNetworkReply> #include <QtQml/QQmlListProperty> -#include <qgeopositioninfo.h> +#include <QtPositioning/QGeoPositionInfoSource> //! [0] class WeatherData : public QObject { @@ -146,6 +146,7 @@ public slots: private slots: void networkSessionOpened(); void positionUpdated(QGeoPositionInfo gpsPos); + void positionError(QGeoPositionInfoSource::Error e); // these would have QNetworkReply* params but for the signalmapper void handleGeoNetworkData(QObject *networkReply); void handleWeatherNetworkData(QObject *networkReply); |