diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-09-12 04:52:41 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-09-12 04:52:41 +0200 |
commit | 167509514587aa22d837b42a8d30d7c1128e0a45 (patch) | |
tree | 614b9fdd0dce4b2cdbc4dea44f353306d1dbe276 | |
parent | 06a4fbb5c0ad0fadba1e5924f73d067850a78312 (diff) | |
download | libquotient-167509514587aa22d837b42a8d30d7c1128e0a45.tar.gz libquotient-167509514587aa22d837b42a8d30d7c1128e0a45.zip |
Fix building with older Qt
-rw-r--r-- | quotest/quotest.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/quotest/quotest.cpp b/quotest/quotest.cpp index 3f886676..31a0b6d6 100644 --- a/quotest/quotest.cpp +++ b/quotest/quotest.cpp @@ -438,21 +438,30 @@ TEST_IMPL(sendFile) return false; } +// Can be replaced with a lambda once QtConcurrent is able to resolve return +// types from lambda invocations (Qt 6 can, not sure about earlier) +struct DownloadRunner { + QUrl url; + + using result_type = QNetworkReply::NetworkError; + + QNetworkReply::NetworkError operator()(int) const { + QEventLoop el; + auto reply = NetworkAccessManager::instance()->get(QNetworkRequest(url)); + QObject::connect( + reply, &QNetworkReply::finished, &el, [&el] { el.exit(); }, + Qt::QueuedConnection); + el.exec(); + return reply->error(); + } +}; + bool testDownload(const QUrl& url) { // Move out actual test from the multithreaded code // to help debugging - auto results = - QtConcurrent::blockingMapped(QVector<int> { 1, 2, 3 }, [url](int) { - QEventLoop el; - auto reply = - NetworkAccessManager::instance()->get(QNetworkRequest(url)); - QObject::connect( - reply, &QNetworkReply::finished, &el, [&el] { el.exit(); }, - Qt::QueuedConnection); - el.exec(); - return reply->error(); - }); + auto results = QtConcurrent::blockingMapped(QVector<int> { 1, 2, 3 }, + DownloadRunner { url }); return std::all_of(results.cbegin(), results.cend(), [](QNetworkReply::NetworkError ne) { return ne == QNetworkReply::NoError; |