Found during T149, use QScopedPointer to destroy QNetworkReply

This commit is contained in:
Klaus Basan
2017-09-10 23:23:11 +02:00
committed by Mathew Sutcliffe
parent a22cd134f8
commit 099afba8a7
2 changed files with 9 additions and 6 deletions

View File

@@ -99,16 +99,19 @@ namespace BlackWxPlugin
emit fetchingFinished(); emit fetchingFinished();
} }
void CWeatherDataGfs::ps_parseGfsFile(QNetworkReply *reply) void CWeatherDataGfs::ps_parseGfsFile(QNetworkReply *nwReplyPtr)
{ {
m_gribData = reply->readAll(); // wrap pointer, make sure any exit cleans up reply
// required to use delete later as object is created in a different thread
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
m_gribData = nwReply->readAll();
Q_ASSERT_X(!m_parseGribFileWorker, Q_FUNC_INFO, "Worker already running"); Q_ASSERT_X(!m_parseGribFileWorker, Q_FUNC_INFO, "Worker already running");
m_parseGribFileWorker = BlackMisc::CWorker::fromTask(this, "parseGribFile", [this]() m_parseGribFileWorker = BlackMisc::CWorker::fromTask(this, "parseGribFile", [this]()
{ {
parseGfsFileImpl(m_gribData); parseGfsFileImpl(m_gribData);
}); });
m_parseGribFileWorker->then(this, &CWeatherDataGfs::ps_fetchingWeatherDataFinished); m_parseGribFileWorker->then(this, &CWeatherDataGfs::ps_fetchingWeatherDataFinished);
reply->deleteLater();
} }
QUrl CWeatherDataGfs::getDownloadUrl() const QUrl CWeatherDataGfs::getDownloadUrl() const
@@ -211,7 +214,7 @@ namespace BlackWxPlugin
g2int iseek = 0; g2int iseek = 0;
for (;;) for (;;)
{ {
if(QThread::currentThread()->isInterruptionRequested()) { return; } if (QThread::currentThread()->isInterruptionRequested()) { return; }
// Search next grib field // Search next grib field
g2int lskip = 0; g2int lskip = 0;
@@ -260,7 +263,7 @@ namespace BlackWxPlugin
for (const GfsGridPoint &gfsGridPoint : as_const(m_gfsWeatherGrid)) for (const GfsGridPoint &gfsGridPoint : as_const(m_gfsWeatherGrid))
{ {
if(QThread::currentThread()->isInterruptionRequested()) { return; } if (QThread::currentThread()->isInterruptionRequested()) { return; }
CTemperatureLayerList temperatureLayers; CTemperatureLayerList temperatureLayers;

View File

@@ -58,7 +58,7 @@ namespace BlackWxPlugin
void ps_fetchingWeatherDataFinished(); void ps_fetchingWeatherDataFinished();
//! Parsing //! Parsing
void ps_parseGfsFile(QNetworkReply *reply); void ps_parseGfsFile(QNetworkReply *nwReplyPtr);
private: private:
enum Grib2CloudLevel enum Grib2CloudLevel