diff --git a/src/concurrent/qtconcurrentrunbase.h b/src/concurrent/qtconcurrentrunbase.h index 5e9fa0aa00..176097c04f 100644 --- a/src/concurrent/qtconcurrentrunbase.h +++ b/src/concurrent/qtconcurrentrunbase.h @@ -100,14 +100,6 @@ public: // For backward compatibility QFuture start(QThreadPool *pool) { return start({pool, 0}); } - void run() override {} - virtual void runFunctor() = 0; -}; - -template -class RunFunctionTask : public RunFunctionTaskBase -{ -public: void run() override { if (this->isCanceled()) { @@ -117,7 +109,7 @@ public: #ifndef QT_NO_EXCEPTIONS try { #endif - this->runFunctor(); + runFunctor(); #ifndef QT_NO_EXCEPTIONS } catch (QException &e) { QFutureInterface::reportException(e); @@ -126,40 +118,33 @@ public: } #endif + reportResult(); + + this->reportFinished(); + } + +protected: + virtual void runFunctor() = 0; + virtual void reportResult() {} +}; + +template +class RunFunctionTask : public RunFunctionTaskBase +{ +protected: + void reportResult() override + { if constexpr (std::is_move_constructible_v) this->reportAndMoveResult(std::move(result)); else if constexpr (std::is_copy_constructible_v) this->reportResult(result); - - this->reportFinished(); } + T result; }; template <> -class RunFunctionTask : public RunFunctionTaskBase -{ -public: - void run() override - { - if (this->isCanceled()) { - this->reportFinished(); - return; - } -#ifndef QT_NO_EXCEPTIONS - try { -#endif - this->runFunctor(); -#ifndef QT_NO_EXCEPTIONS - } catch (QException &e) { - QFutureInterface::reportException(e); - } catch (...) { - QFutureInterface::reportException(QUnhandledException()); - } -#endif - this->reportFinished(); - } -}; +class RunFunctionTask : public RunFunctionTaskBase {}; } //namespace QtConcurrent diff --git a/src/concurrent/qtconcurrentstoredfunctioncall.h b/src/concurrent/qtconcurrentstoredfunctioncall.h index b879e8af45..f6d47f5119 100644 --- a/src/concurrent/qtconcurrentstoredfunctioncall.h +++ b/src/concurrent/qtconcurrentstoredfunctioncall.h @@ -78,6 +78,7 @@ struct StoredFunctionCall : public RunFunctionTask, @@ -89,6 +90,7 @@ struct StoredFunctionCall : public RunFunctionTaskresult = std::apply(invoke, std::move(data)); } +private: DecayedTuple data; };