diff --git a/src/GUI/app.cpp b/src/GUI/app.cpp index db01a868..1d1f2ea9 100644 --- a/src/GUI/app.cpp +++ b/src/GUI/app.cpp @@ -38,7 +38,6 @@ App::App(int &argc, char **argv) : QApplication(argc, argv), #endif // Q_OS_MAC QNetworkProxyFactory::setUseSystemConfiguration(true); - Downloader::setNetworkAccessManager(new QNetworkAccessManager(this)); QSettings settings(APP_NAME, APP_NAME); settings.beginGroup(OPTIONS_SETTINGS_GROUP); #ifdef ENABLE_HTTP2 diff --git a/src/map/downloader.cpp b/src/map/downloader.cpp index acd2ebec..d992ab6a 100644 --- a/src/map/downloader.cpp +++ b/src/map/downloader.cpp @@ -80,12 +80,17 @@ private: }; -QNetworkAccessManager *Downloader::_manager = 0; int Downloader::_timeout = 30; #ifdef ENABLE_HTTP2 bool Downloader::_http2 = true; #endif // ENABLE_HTTP2 +QNetworkAccessManager *Downloader::manager() +{ + static QNetworkAccessManager manager; + return &manager; +} + bool Downloader::doDownload(const Download &dl, const QByteArray &authorization, const Redirect *redirect) { @@ -118,7 +123,7 @@ bool Downloader::doDownload(const Download &dl, QVariant(_http2)); #endif // ENABLE_HTTP2 - QNetworkReply *reply = _manager->get(request); + QNetworkReply *reply = manager()->get(request); if (reply && reply->isRunning()) { _currentDownloads.insert(url); ReplyTimeout::setTimeout(reply, _timeout); @@ -232,6 +237,6 @@ bool Downloader::get(const QList &list, void Downloader::enableHTTP2(bool enable) { _http2 = enable; - _manager->clearConnectionCache(); + manager()->clearConnectionCache(); } #endif // ENABLE_HTTP2 diff --git a/src/map/downloader.h b/src/map/downloader.h index d46a1e47..33d5e1cd 100644 --- a/src/map/downloader.h +++ b/src/map/downloader.h @@ -50,8 +50,6 @@ public: #ifdef ENABLE_HTTP2 static void enableHTTP2(bool enable); #endif // ENABLE_HTTP2 - static void setNetworkAccessManager(QNetworkAccessManager *manager) - {_manager = manager;} signals: void finished(); @@ -69,6 +67,8 @@ private: const Redirect *redirect = 0); bool saveToDisk(const QString &filename, QIODevice *data); + static QNetworkAccessManager *manager(); + QSet _currentDownloads; QHash _errorDownloads; @@ -76,7 +76,6 @@ private: #ifdef ENABLE_HTTP2 static bool _http2; #endif // ENABLE_HTTP2 - static QNetworkAccessManager *_manager; }; #endif // DOWNLOADER_H