From c22fcd0c5e0308a83279473a1837ffbfe419beb9 Mon Sep 17 00:00:00 2001 From: hemirt Date: Sun, 1 Oct 2017 00:48:24 +0200 Subject: [PATCH] ImageLoader detach --- src/messages/imageloader.cpp | 17 +++++------------ src/messages/imageloader.hpp | 2 -- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/messages/imageloader.cpp b/src/messages/imageloader.cpp index 22ce1c5b0..c7a88c695 100644 --- a/src/messages/imageloader.cpp +++ b/src/messages/imageloader.cpp @@ -18,7 +18,7 @@ namespace messages { ImageLoader::ImageLoader() { - this->worker = std::thread(&ImageLoader::run, this); + std::thread(&ImageLoader::run, this).detach(); } ImageLoader::~ImageLoader() @@ -29,14 +29,10 @@ ImageLoader::~ImageLoader() this->ready = true; } this->cv.notify_all(); - qDebug() << "notified waiting"; - this->worker.join(); - qDebug() << "destruct"; } void ImageLoader::run() { - this->eventLoop.reset(new QEventLoop()); while (true) { std::unique_lock lk(this->workerM); if (!this->ready) { @@ -52,17 +48,14 @@ void ImageLoader::run() this->ready = false; lk.unlock(); for (auto &lli : current) { - if (this->exit) - return; QNetworkRequest request; request.setUrl(QUrl(lli->url)); QNetworkAccessManager NaM; QNetworkReply *reply = NaM.get(request); - QObject::connect(reply, &QNetworkReply::finished, this->eventLoop.get(), - &QEventLoop::quit); - qDebug() << "eve1"; - this->eventLoop->exec(); // Wait until response is read. - qDebug() << "eve2"; + QEventLoop eventLoop; + QObject::connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit); + // Wait until response is read. + eventLoop.exec(); qDebug() << "Received emote " << lli->url; QByteArray array = reply->readAll(); QBuffer buffer(&array); diff --git a/src/messages/imageloader.hpp b/src/messages/imageloader.hpp index 83b776b7b..01d3c334f 100644 --- a/src/messages/imageloader.hpp +++ b/src/messages/imageloader.hpp @@ -22,13 +22,11 @@ public: private: void run(); - std::thread worker; std::mutex workerM; std::vector toProcess; bool ready = false; std::condition_variable cv; bool exit = false; - std::unique_ptr eventLoop; }; } // namespace messages