Skip to content

Commit 748ef0d

Browse files
committed
Fixed a crash when no internet connection (2)
1 parent 1665a12 commit 748ef0d

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

core/PropConditions.cpp

+19-8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ void PropConditions::updateDxTrends()
7474
FCT_IDENTIFICATION;
7575

7676
dxTrendResult.clear();
77+
dxTrendTimeoutTimer.stop();
78+
dxTrendPendingConnections.clear(); // pending connections will be ignored.
7779

7880
for ( const QString& continent : Data::getContinentList() )
7981
dxTrendPendingConnections << nam->get(prepareRequest(QUrl(DXC_TRENDS + QString("/%0/15").arg(continent))));
@@ -209,9 +211,9 @@ void PropConditions::processReply(QNetworkReply* reply)
209211
emit mufMapUpdated();
210212
}
211213
}
212-
else if ( replyURL.toString().contains(DXC_TRENDS) )
214+
else if ( dxTrendPendingConnections.contains(reply) )
213215
{
214-
dxTrendPendingConnections.removeAll(reply);
216+
dxTrendPendingConnections.remove(reply);
215217

216218
QJsonDocument doc = QJsonDocument::fromJson(data);
217219
const QString &requestContinent = replyURL.path().section('/', -2, -2);
@@ -247,7 +249,7 @@ void PropConditions::processReply(QNetworkReply* reply)
247249
else
248250
{
249251
qCDebug(runtime) << "HTTP Status Code" << replyStatusCode;
250-
dxTrendPendingConnections.removeAll(reply);
252+
dxTrendPendingConnections.remove(reply);
251253
repeateRequest(reply->url());
252254
reply->deleteLater();
253255
}
@@ -267,7 +269,10 @@ void PropConditions::repeateRequest(const QUrl &url)
267269
QTimer::singleShot(1000 * RESEND_BASE_INTERVAL * failedRequests[url], this, [this, url]()
268270
{
269271
qCDebug(runtime) << "Resending request" << url.toString();
270-
nam->get(prepareRequest(url));
272+
QNetworkReply *req = nam->get(prepareRequest(url));
273+
if ( url.toString().contains(DXC_TRENDS))
274+
dxTrendPendingConnections << req;
275+
271276
});
272277
}
273278
else
@@ -291,18 +296,24 @@ void PropConditions::dxTrendTimeout()
291296

292297
dxTrendTimeoutTimer.stop();
293298

294-
for ( auto it = dxTrendPendingConnections.begin(); it != dxTrendPendingConnections.end(); ++it )
299+
for ( auto it = dxTrendPendingConnections.begin(); it != dxTrendPendingConnections.end(); )
295300
{
296-
(*it)->abort();
297-
(*it)->deleteLater();
301+
QNetworkReply* reply = *it;
302+
it = dxTrendPendingConnections.erase(it);
303+
if ( reply )
304+
{
305+
reply->abort();
306+
reply->deleteLater();
307+
}
298308
}
309+
310+
dxTrendPendingConnections.clear();
299311
dxTrendResult.clear();
300312
emit dxTrendFinalized(dxTrendResult); // emit empty result
301313
}
302314

303315
PropConditions::~PropConditions()
304316
{
305-
dxTrendTimeoutTimer.stop();
306317
dxTrendTimeout();
307318
nam->deleteLater();
308319
}

core/PropConditions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <QObject>
55
#include <QDateTime>
6-
#include <QVector>
6+
#include <QSet>
77
#include <QTimer>
88

99
class QNetworkAccessManager;
@@ -104,7 +104,7 @@ public slots:
104104
GenericValueMap<double> auroraMap;
105105
GenericValueMap<double> mufMap;
106106
QHash<QUrl, int> failedRequests;
107-
QList<QNetworkReply *> dxTrendPendingConnections;
107+
QSet<QNetworkReply *> dxTrendPendingConnections;
108108
QTimer dxTrendTimeoutTimer;
109109
QHash<QString, QHash<QString, QHash<QString, int>>> dxTrendResult;
110110
QByteArray agentString;

0 commit comments

Comments
 (0)