summaryrefslogtreecommitdiff
path: root/examples/positioning/weatherinfo
diff options
context:
space:
mode:
Diffstat (limited to 'examples/positioning/weatherinfo')
-rw-r--r--examples/positioning/weatherinfo/appmodel.cpp46
-rw-r--r--examples/positioning/weatherinfo/appmodel.h1
-rw-r--r--examples/positioning/weatherinfo/doc/src/weatherinfo.qdoc14
-rw-r--r--examples/positioning/weatherinfo/weatherinfo.pro1
4 files changed, 17 insertions, 45 deletions
diff --git a/examples/positioning/weatherinfo/appmodel.cpp b/examples/positioning/weatherinfo/appmodel.cpp
index 93186aea..6d31d5ba 100644
--- a/examples/positioning/weatherinfo/appmodel.cpp
+++ b/examples/positioning/weatherinfo/appmodel.cpp
@@ -55,7 +55,6 @@
#include <qnmeapositioninfosource.h>
#include <qgeopositioninfo.h>
#include <qnetworkconfigmanager.h>
-#include <qnetworksession.h>
#include <QJsonDocument>
#include <QJsonObject>
@@ -150,7 +149,6 @@ public:
QString longitude, latitude;
QString city;
QNetworkAccessManager *nam;
- QNetworkSession *ns;
WeatherData now;
QList<WeatherData*> forecast;
QQmlListProperty<WeatherData> *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()
{
@@ -347,7 +327,7 @@ void AppModel::handleGeoNetworkData(QNetworkReply *networkReply)
return;
}
- if (!networkReply->networkError()) {
+ if (!networkReply->error()) {
d->nErrors = 0;
if (!d->throttle.isValid())
d->throttle.start();
@@ -403,7 +383,7 @@ void AppModel::handleWeatherNetworkData(QNetworkReply *networkReply)
if (!networkReply)
return;
- if (!networkReply->networkError()) {
+ if (!networkReply->error()) {
foreach (WeatherData *inf, d->forecast)
delete inf;
d->forecast.clear();
@@ -455,7 +435,7 @@ void AppModel::handleForecastNetworkData(QNetworkReply *networkReply)
if (!networkReply)
return;
- if (!networkReply->networkError()) {
+ if (!networkReply->error()) {
QJsonDocument document = QJsonDocument::fromJson(networkReply->readAll());
QJsonObject jo;
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