From a95c1e3a7cf55a43ba1a8b963aa0c0df02655747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 14 Feb 2020 16:25:01 +0100 Subject: Remove use of bearer management from weatherinfo example Change-Id: I8740a008b43b8a5476bdb3506e763acb4bd1b454 Reviewed-by: Timur Pocheptsov Reviewed-by: Alex Blasche --- examples/positioning/weatherinfo/appmodel.cpp | 40 ++++++---------------- examples/positioning/weatherinfo/appmodel.h | 1 - .../weatherinfo/doc/src/weatherinfo.qdoc | 14 +++----- examples/positioning/weatherinfo/weatherinfo.pro | 1 - 4 files changed, 14 insertions(+), 42 deletions(-) diff --git a/examples/positioning/weatherinfo/appmodel.cpp b/examples/positioning/weatherinfo/appmodel.cpp index 93186aea..bace7510 100644 --- a/examples/positioning/weatherinfo/appmodel.cpp +++ b/examples/positioning/weatherinfo/appmodel.cpp @@ -55,7 +55,6 @@ #include #include #include -#include #include #include @@ -150,7 +149,6 @@ public: QString longitude, latitude; QString city; QNetworkAccessManager *nam; - QNetworkSession *ns; WeatherData now; QList forecast; QQmlListProperty *fcProp; @@ -166,7 +164,6 @@ public: AppModelPrivate() : src(NULL), nam(NULL), - ns(NULL), fcProp(NULL), ready(false), useGps(true), @@ -225,31 +222,7 @@ AppModel::AppModel(QObject *parent) : //! [1] - // make sure we have an active network session d->nam = new QNetworkAccessManager(this); - - QNetworkConfigurationManager ncm; - d->ns = new QNetworkSession(ncm.defaultConfiguration(), this); - connect(d->ns, SIGNAL(opened()), this, SLOT(networkSessionOpened())); - // the session may be already open. if it is, run the slot directly - if (d->ns->isOpen()) - this->networkSessionOpened(); - // tell the system we want network - d->ns->open(); -} -//! [1] - -AppModel::~AppModel() -{ - d->ns->close(); - if (d->src) - d->src->stopUpdates(); - delete d; -} - -//! [2] -void AppModel::networkSessionOpened() -{ d->src = QGeoPositionInfoSource::createDefaultSource(this); if (d->src) { @@ -266,9 +239,16 @@ void AppModel::networkSessionOpened() this->refreshWeather(); } } -//! [2] +//! [1] + +AppModel::~AppModel() +{ + if (d->src) + d->src->stopUpdates(); + delete d; +} -//! [3] +//! [2] void AppModel::positionUpdated(QGeoPositionInfo gpsPos) { d->coord = gpsPos.coordinate(); @@ -278,7 +258,7 @@ void AppModel::positionUpdated(QGeoPositionInfo gpsPos) queryCity(); } -//! [3] +//! [2] void AppModel::queryCity() { diff --git a/examples/positioning/weatherinfo/appmodel.h b/examples/positioning/weatherinfo/appmodel.h index a4d4e87a..f6657a59 100644 --- a/examples/positioning/weatherinfo/appmodel.h +++ b/examples/positioning/weatherinfo/appmodel.h @@ -156,7 +156,6 @@ public slots: //! [2] private slots: void queryCity(); - void networkSessionOpened(); void positionUpdated(QGeoPositionInfo gpsPos); void positionError(QGeoPositionInfoSource::Error e); void handleGeoNetworkData(QNetworkReply *networkReply); diff --git a/examples/positioning/weatherinfo/doc/src/weatherinfo.qdoc b/examples/positioning/weatherinfo/doc/src/weatherinfo.qdoc index 089ae9d3..33a95f70 100644 --- a/examples/positioning/weatherinfo/doc/src/weatherinfo.qdoc +++ b/examples/positioning/weatherinfo/doc/src/weatherinfo.qdoc @@ -55,19 +55,13 @@ \snippet weatherinfo/appmodel.h 0 \snippet weatherinfo/appmodel.h 1 - AppModel models the state of the entire application. At startup, the - application first begins by waiting for network connectivity. We do - this using the QNetworkConfigurationManager and QNetworkSession family - of C++ APIs. + AppModel models the state of the entire application. At startup, we + get the platform's default position source using + QGeoPositionInfo::createDefaultSource() \snippet weatherinfo/appmodel.cpp 0 \snippet weatherinfo/appmodel.cpp 1 - Once the network session is open, we proceed to get the platform's - default position source using QGeoPositionInfo::createDefaultSource() - - \snippet weatherinfo/appmodel.cpp 2 - If no default source is available, we take a static position and fetch weather for that. If, however, we do have a position source, we connect its positionUpdated() signal to a slot on the AppModel and call @@ -77,7 +71,7 @@ of the returned coordinate to retrieve the current "city" name for use in the weather lookup. - \snippet weatherinfo/appmodel.cpp 3 + \snippet weatherinfo/appmodel.cpp 2 To inform the UI about this process, the cityChanged() signal is emitted when a new city is used, and the weatherChanged() signal whenever a diff --git a/examples/positioning/weatherinfo/weatherinfo.pro b/examples/positioning/weatherinfo/weatherinfo.pro index d8f9675a..e2b2102d 100644 --- a/examples/positioning/weatherinfo/weatherinfo.pro +++ b/examples/positioning/weatherinfo/weatherinfo.pro @@ -2,7 +2,6 @@ TEMPLATE = app TARGET = weatherinfo QT += core network positioning qml quick -requires(qtConfig(bearermanagement)) SOURCES += main.cpp \ appmodel.cpp -- cgit v1.2.1