From a36d9e67e3b8168cb4d1eb76eda96ebb8242fd20 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 12 Aug 2014 16:18:53 +0200 Subject: Don't hang weatherinfo if position source has an error. We continue with the simulation mode. Task-number: QTBUG-40702 Change-Id: I130b0080a198a218803986fb7ff06fdd0b83186a Reviewed-by: Aaron McCarthy --- examples/positioning/weatherinfo/appmodel.cpp | 17 +++++++++++++++++ examples/positioning/weatherinfo/appmodel.h | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'examples/positioning') 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(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 #include -#include +#include //! [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); -- cgit v1.2.3