Run reply processing in thread pool

This commit is contained in:
RickyRister 2025-08-11 00:37:04 -07:00
parent d7000fbcb0
commit 155448d361
3 changed files with 13 additions and 2 deletions

View file

@ -94,7 +94,7 @@ QNetworkReply *PictureLoaderWorker::makeRequest(const QUrl &url, PictureLoaderWo
QNetworkReply *reply = networkManager->get(req);
// Connect reply handling
connect(reply, &QNetworkReply::finished, worker, [reply, worker] { worker->handleNetworkReply(reply); });
connect(reply, &QNetworkReply::finished, worker, [reply, worker] { worker->acceptNetworkReply(reply); });
return reply;
}

View file

@ -11,6 +11,7 @@
#include <QNetworkDiskCache>
#include <QNetworkReply>
#include <QThread>
#include <QThreadPool>
// Card back returned by gatherer when card is not found
static const QStringList MD5_BLACKLIST = {"db0c48db407a907c16ade38de048a441"};
@ -69,6 +70,15 @@ void PictureLoaderWorkerWork::picDownloadFailed()
}
}
/**
* Processes the reply in another thread.
* @param reply The finished reply. Takes ownership of the object
*/
void PictureLoaderWorkerWork::acceptNetworkReply(QNetworkReply *reply)
{
QThreadPool::globalInstance()->start([this, reply] { handleNetworkReply(reply); });
}
/**
*
* @param reply The reply. Takes ownership of the object

View file

@ -30,13 +30,14 @@ public:
PictureToLoad cardToDownload;
public slots:
void handleNetworkReply(QNetworkReply *reply);
void acceptNetworkReply(QNetworkReply *reply);
private:
bool picDownload;
void startNextPicDownload();
void picDownloadFailed();
void handleNetworkReply(QNetworkReply *reply);
void handleFailedReply(const QNetworkReply *reply);
void handleSuccessfulReply(QNetworkReply *reply);
QImage tryLoadImageFromReply(QNetworkReply *reply);