summaryrefslogtreecommitdiffstats
path: root/examples/positioning/weatherinfo/appmodel.cpp
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2017-03-20 17:26:47 +0300
committerAlexander Volkov <a.volkov@rusbitech.ru>2017-04-03 20:21:34 +0000
commit8bfc247bd4616fa7472ea1ae65ee72650d40c12f (patch)
tree5b8a93d3facf56e87f35582616df34d644a23bd0 /examples/positioning/weatherinfo/appmodel.cpp
parent22090b374f1f6e53a28188f91cca8b860c859555 (diff)
weatherinfo example: use lambdas instead of QSignalMapper
QSignalMapper is deprecated since Qt 5.10. Besides code looks clearer with lambdas. Change-Id: I7e4681e0d6b354cd8da9a4506dad917799688dc9 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'examples/positioning/weatherinfo/appmodel.cpp')
-rw-r--r--examples/positioning/weatherinfo/appmodel.cpp36
1 files changed, 9 insertions, 27 deletions
diff --git a/examples/positioning/weatherinfo/appmodel.cpp b/examples/positioning/weatherinfo/appmodel.cpp
index 4d8806b8..f17d8141 100644
--- a/examples/positioning/weatherinfo/appmodel.cpp
+++ b/examples/positioning/weatherinfo/appmodel.cpp
@@ -47,7 +47,6 @@
#include <qnetworkconfigmanager.h>
#include <qnetworksession.h>
-#include <QSignalMapper>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
@@ -145,8 +144,6 @@ public:
WeatherData now;
QList<WeatherData*> forecast;
QQmlListProperty<WeatherData> *fcProp;
- QSignalMapper *geoReplyMapper;
- QSignalMapper *weatherReplyMapper, *forecastReplyMapper;
bool ready;
bool useGps;
QElapsedTimer throttle;
@@ -210,16 +207,6 @@ AppModel::AppModel(QObject *parent) :
forecastAt,
forecastClear);
- d->geoReplyMapper = new QSignalMapper(this);
- d->weatherReplyMapper = new QSignalMapper(this);
- d->forecastReplyMapper = new QSignalMapper(this);
-
- connect(d->geoReplyMapper, SIGNAL(mapped(QObject*)),
- this, SLOT(handleGeoNetworkData(QObject*)));
- connect(d->weatherReplyMapper, SIGNAL(mapped(QObject*)),
- this, SLOT(handleWeatherNetworkData(QObject*)));
- connect(d->forecastReplyMapper, SIGNAL(mapped(QObject*)),
- this, SLOT(handleForecastNetworkData(QObject*)));
connect(&d->delayedCityRequestTimer, SIGNAL(timeout()),
this, SLOT(queryCity()));
connect(&d->requestNewWeatherTimer, SIGNAL(timeout()),
@@ -312,9 +299,8 @@ void AppModel::queryCity()
QNetworkReply *rep = d->nam->get(QNetworkRequest(url));
// connect up the signal right away
- d->geoReplyMapper->setMapping(rep, rep);
- connect(rep, SIGNAL(finished()),
- d->geoReplyMapper, SLOT(map()));
+ connect(rep, &QNetworkReply::finished,
+ this, [this, rep]() { handleGeoNetworkData(rep); });
}
void AppModel::positionError(QGeoPositionInfoSource::Error e)
@@ -344,9 +330,8 @@ void AppModel::hadError(bool tryAgain)
d->delayedCityRequestTimer.start();
}
-void AppModel::handleGeoNetworkData(QObject *replyObj)
+void AppModel::handleGeoNetworkData(QNetworkReply *networkReply)
{
- QNetworkReply *networkReply = qobject_cast<QNetworkReply*>(replyObj);
if (!networkReply) {
hadError(false); // should retry?
return;
@@ -393,9 +378,8 @@ void AppModel::refreshWeather()
QNetworkReply *rep = d->nam->get(QNetworkRequest(url));
// connect up the signal right away
- d->weatherReplyMapper->setMapping(rep, rep);
- connect(rep, SIGNAL(finished()),
- d->weatherReplyMapper, SLOT(map()));
+ connect(rep, &QNetworkReply::finished,
+ this, [this, rep]() { handleWeatherNetworkData(rep); });
}
static QString niceTemperatureString(double t)
@@ -403,10 +387,9 @@ static QString niceTemperatureString(double t)
return QString::number(qRound(t-ZERO_KELVIN)) + QChar(0xB0);
}
-void AppModel::handleWeatherNetworkData(QObject *replyObj)
+void AppModel::handleWeatherNetworkData(QNetworkReply *networkReply)
{
qCDebug(requestsLog) << "got weather network data";
- QNetworkReply *networkReply = qobject_cast<QNetworkReply*>(replyObj);
if (!networkReply)
return;
@@ -452,14 +435,13 @@ void AppModel::handleWeatherNetworkData(QObject *replyObj)
QNetworkReply *rep = d->nam->get(QNetworkRequest(url));
// connect up the signal right away
- d->forecastReplyMapper->setMapping(rep, rep);
- connect(rep, SIGNAL(finished()), d->forecastReplyMapper, SLOT(map()));
+ connect(rep, &QNetworkReply::finished,
+ this, [this, rep]() { handleForecastNetworkData(rep); });
}
-void AppModel::handleForecastNetworkData(QObject *replyObj)
+void AppModel::handleForecastNetworkData(QNetworkReply *networkReply)
{
qCDebug(requestsLog) << "got forecast";
- QNetworkReply *networkReply = qobject_cast<QNetworkReply*>(replyObj);
if (!networkReply)
return;