diff options
Diffstat (limited to 'src/concurrent/qtconcurrentrunbase.h')
-rw-r--r-- | src/concurrent/qtconcurrentrunbase.h | 53 |
1 files changed, 19 insertions, 34 deletions
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<T> start(QThreadPool *pool) { return start({pool, 0}); } - void run() override {} - virtual void runFunctor() = 0; -}; - -template <typename T> -class RunFunctionTask : public RunFunctionTaskBase<T> -{ -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<T>::reportException(e); @@ -126,41 +118,34 @@ public: } #endif - if constexpr (std::is_move_constructible_v<T>) - this->reportAndMoveResult(std::move(result)); - else if constexpr (std::is_copy_constructible_v<T>) - this->reportResult(result); + reportResult(); this->reportFinished(); } - T result; + +protected: + virtual void runFunctor() = 0; + virtual void reportResult() {} }; -template <> -class RunFunctionTask<void> : public RunFunctionTaskBase<void> +template <typename T> +class RunFunctionTask : public RunFunctionTaskBase<T> { -public: - void run() override +protected: + void reportResult() override { - if (this->isCanceled()) { - this->reportFinished(); - return; - } -#ifndef QT_NO_EXCEPTIONS - try { -#endif - this->runFunctor(); -#ifndef QT_NO_EXCEPTIONS - } catch (QException &e) { - QFutureInterface<void>::reportException(e); - } catch (...) { - QFutureInterface<void>::reportException(QUnhandledException()); - } -#endif - this->reportFinished(); + if constexpr (std::is_move_constructible_v<T>) + this->reportAndMoveResult(std::move(result)); + else if constexpr (std::is_copy_constructible_v<T>) + this->reportResult(result); } + + T result; }; +template <> +class RunFunctionTask<void> : public RunFunctionTaskBase<void> {}; + } //namespace QtConcurrent #endif //Q_QDOC |