diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-08-17 16:00:26 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-18 17:16:40 +0000 |
commit | 4d942551492378adaddca55cb1a48c11e7ec6a3a (patch) | |
tree | fd7fcea8b4e49c4c88726288ae7da725d9842e2e /tests | |
parent | 89760e011555ae375e687daf9d7c4e1333a33797 (diff) |
QtConcurrent::run: support non default-constructible return types
The QtConcurrent::RunFunctionTask class keeps a variable to store the
result of QtConcurrent::run when it becomes available, so that it can be
reported afterwards. This requires the result type to be
default-constructible. However there's no need in storing the result, it
can be reported immediately after it becomes available.
Fixes: QTBUG-95214
Change-Id: I95f3dbff0ab41eaa81b104a8834b37d10a0d193a
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
(cherry picked from commit 642b9fce81b46e23b35b17e8284bd81bdba57fdd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp | 12 | ||||
-rw-r--r-- | tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp | 8 |
2 files changed, 16 insertions, 4 deletions
diff --git a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp index 1b0b9577cf..235ffca0fc 100644 --- a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp +++ b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp @@ -64,6 +64,7 @@ private slots: void moveOnlyType(); void crefFunction(); void customPromise(); + void nonDefaultConstructibleValue(); }; void light() @@ -1564,6 +1565,17 @@ void tst_QtConcurrentRun::customPromise() QCOMPARE(p.future().progressMaximum(), 10); } +void tst_QtConcurrentRun::nonDefaultConstructibleValue() +{ + struct NonDefaultConstructible + { + explicit NonDefaultConstructible(int v) : value(v) { } + int value = 0; + }; + + auto future = QtConcurrent::run([] { return NonDefaultConstructible(42); }); + QCOMPARE(future.result().value, 42); +} QTEST_MAIN(tst_QtConcurrentRun) #include "tst_qtconcurrentrun.moc" diff --git a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp index 929047c07e..33ecfb9cab 100644 --- a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp +++ b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp @@ -229,12 +229,12 @@ void tst_QFutureWatcher::canceled() future.waitForFinished(); } -class IntTask : public RunFunctionTask<int> +class IntTask : public RunFunctionTaskBase<int> { public: void runFunctor() override { - result = 10; + promise.reportResult(10); } }; @@ -463,7 +463,7 @@ void tst_QFutureWatcher::disconnectRunningFuture() } const int maxProgress = 100000; -class ProgressEmitterTask : public RunFunctionTask<void> +class ProgressEmitterTask : public RunFunctionTaskBase<void> { public: void runFunctor() override @@ -493,7 +493,7 @@ void tst_QFutureWatcher::tooMuchProgress() } template <typename T> -class ProgressTextTask : public RunFunctionTask<T> +class ProgressTextTask : public RunFunctionTaskBase<T> { public: void runFunctor() override |