From f8084ad58c14f2dffe67ca0b7d56d556ccfa7c57 Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Sun, 24 Apr 2022 10:36:22 +0200 Subject: [PATCH] Fix QtConcurrent missing return value --- ScreenPlay/inc/public/ScreenPlay/util.h | 1 + ScreenPlay/inc/public/ScreenPlay/wizards.h | 3 ++ ScreenPlay/src/util.cpp | 22 ++++++------ ScreenPlay/src/wizards.cpp | 41 ++++++++++++++++++---- 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/ScreenPlay/inc/public/ScreenPlay/util.h b/ScreenPlay/inc/public/ScreenPlay/util.h index 5225c323..ec7ed286 100644 --- a/ScreenPlay/inc/public/ScreenPlay/util.h +++ b/ScreenPlay/inc/public/ScreenPlay/util.h @@ -146,6 +146,7 @@ private: QNetworkAccessManager* m_networkAccessManager { nullptr }; QString m_debugMessages {}; + QFuture m_requestAllLicensesFuture; }; // Used for redirect content from static logToGui to setDebugMessages diff --git a/ScreenPlay/inc/public/ScreenPlay/wizards.h b/ScreenPlay/inc/public/ScreenPlay/wizards.h index c10c18a8..b0e3b3ed 100644 --- a/ScreenPlay/inc/public/ScreenPlay/wizards.h +++ b/ScreenPlay/inc/public/ScreenPlay/wizards.h @@ -134,5 +134,8 @@ signals: private: const std::shared_ptr m_globalVariables; const std::optional createTemporaryFolder() const; + +private: + QFuture m_wizardFuture; }; } diff --git a/ScreenPlay/src/util.cpp b/ScreenPlay/src/util.cpp index fdd66f17..2f3855b6 100644 --- a/ScreenPlay/src/util.cpp +++ b/ScreenPlay/src/util.cpp @@ -108,8 +108,10 @@ QString Util::toLocal(const QString& url) */ void Util::Util::requestAllLicenses() { + if (m_requestAllLicensesFuture.isStarted()) + return; - QtConcurrent::run([this]() { + m_requestAllLicensesFuture = QtConcurrent::run([this]() { QString tmp; QFile file; QTextStream out(&file); @@ -154,18 +156,16 @@ void Util::Util::requestAllLicenses() */ void Util::Util::requestDataProtection() { - QtConcurrent::run([this]() { - QString tmp; - QFile file; - QTextStream out(&file); + QString tmp; + QFile file; + QTextStream out(&file); - file.setFileName(":/legal/DataProtection.txt"); - file.open(QIODevice::ReadOnly | QIODevice::Text); - tmp += out.readAll(); - file.close(); + file.setFileName(":/legal/DataProtection.txt"); + file.open(QIODevice::ReadOnly | QIODevice::Text); + tmp += out.readAll(); + file.close(); - emit this->allDataProtectionLoaded(tmp); - }); + emit this->allDataProtectionLoaded(tmp); } static const char* diff --git a/ScreenPlay/src/wizards.cpp b/ScreenPlay/src/wizards.cpp index e8ba6717..8d0b9ba8 100644 --- a/ScreenPlay/src/wizards.cpp +++ b/ScreenPlay/src/wizards.cpp @@ -31,8 +31,12 @@ void Wizards::createQMLWidget(const QString& title, const QString& previewThumbnail, const QVector& tags) { + if (m_wizardFuture.isRunning()) { + qWarning() << "Another wizard is already running! Abort."; + return; + } - QtConcurrent::run([=]() { + m_wizardFuture = QtConcurrent::run([=]() { std::optional folderName = createTemporaryFolder(); if (!folderName.has_value()) { @@ -93,7 +97,12 @@ void Wizards::createHTMLWidget(const QString& title, const QString& previewThumbnail, const QVector& tags) { - QtConcurrent::run([=]() { + if (m_wizardFuture.isRunning()) { + qWarning() << "Another wizard is already running! Abort."; + return; + } + + m_wizardFuture = QtConcurrent::run([=]() { std::optional folderName = createTemporaryFolder(); if (!folderName.has_value()) { @@ -156,7 +165,12 @@ void Wizards::createHTMLWallpaper( const QString& previewThumbnail, const QVector& tags) { - QtConcurrent::run([=]() { + if (m_wizardFuture.isRunning()) { + qWarning() << "Another wizard is already running! Abort."; + return; + } + + m_wizardFuture = QtConcurrent::run([=]() { std::optional folderName = createTemporaryFolder(); if (!folderName.has_value()) { @@ -218,7 +232,12 @@ void Wizards::createQMLWallpaper( const QString& previewThumbnail, const QVector& tags) { - QtConcurrent::run([=]() { + if (m_wizardFuture.isRunning()) { + qWarning() << "Another wizard is already running! Abort."; + return; + } + + m_wizardFuture = QtConcurrent::run([=]() { std::optional folderName = createTemporaryFolder(); if (!folderName.has_value()) { @@ -271,7 +290,12 @@ void Wizards::createGifWallpaper( const QString& file, const QVector& tags) { - auto con = QtConcurrent::run([=]() { + if (m_wizardFuture.isRunning()) { + qWarning() << "Another wizard is already running! Abort."; + return; + } + + m_wizardFuture = QtConcurrent::run([=]() { std::optional folderName = createTemporaryFolder(); if (!folderName.has_value()) { @@ -321,7 +345,12 @@ void Wizards::createWebsiteWallpaper( const QUrl& url, const QVector& tags) { - QtConcurrent::run([=]() { + if (m_wizardFuture.isRunning()) { + qWarning() << "Another wizard is already running! Abort."; + return; + } + + m_wizardFuture = QtConcurrent::run([=]() { std::optional folderName = createTemporaryFolder(); if (!folderName.has_value()) {