diff --git a/src/core/networkaccessmanager.cpp b/src/core/networkaccessmanager.cpp index 9dfd1d80f..5fe51df3a 100644 --- a/src/core/networkaccessmanager.cpp +++ b/src/core/networkaccessmanager.cpp @@ -22,6 +22,7 @@ NetworkAccessManager::NetworkAccessManager(QObject* parent, void NetworkAccessManager::Get(const QUrl &url, QObject *receiver, const char *slot, quint64 id, bool force_cache) { + connect(receiver, SIGNAL(destroyed(QObject*)), SLOT(ReceiverDestroyed(QObject*))); QMetaObject::invokeMethod( this, "RunGet", Qt::QueuedConnection, Q_ARG(QUrl, url), Q_ARG(QObject*, receiver), @@ -43,6 +44,13 @@ void NetworkAccessManager::RunGet(const QUrl &url, QObject *receiver, pending_replies_.insert(reply, r); } +void NetworkAccessManager::ReceiverDestroyed(QObject* receiver) { + foreach (QNetworkReply* key, pending_replies_.keys()) { + if (pending_replies_[key].receiver == receiver) + pending_replies_[key].receiver = NULL; + } +} + QNetworkRequest NetworkAccessManager::CreateRequest(const QUrl& url, bool force_cache) { QNetworkRequest req(url); req.setRawHeader("User-Agent", QString("%1 %2").arg( @@ -60,6 +68,9 @@ void NetworkAccessManager::RequestFinished() { QNetworkReply* reply = static_cast(sender()); Receiver r = pending_replies_.take(reply); + if (!r.receiver) + return; + QMetaObject::invokeMethod(r.receiver, r.slot, Q_ARG(quint64, r.id), Q_ARG(QNetworkReply*, reply)); diff --git a/src/core/networkaccessmanager.h b/src/core/networkaccessmanager.h index 9dcca4bfa..2e12cc866 100644 --- a/src/core/networkaccessmanager.h +++ b/src/core/networkaccessmanager.h @@ -31,6 +31,7 @@ class NetworkAccessManager : public QObject { quint64 id, bool force_cache); void RunGetBlocking(const QUrl& url, bool force_cache, QNetworkReply** reply); void RequestFinished(); + void ReceiverDestroyed(QObject* receiver); private: QNetworkRequest CreateRequest(const QUrl& url, bool force_cache);