diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2020-07-26 14:05:24 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2020-08-19 12:46:10 +0200 |
commit | 765f503b1e0b3ab18b1847fb2d91aa3e9da94ecb (patch) | |
tree | 036099821a3b09f7d39e3824a04a7555b696fbdf /src/corelib/thread | |
parent | 0243951e0aba20a010577f09d6486f21d621d575 (diff) |
QtConcurrent: Introduce runWithPromise()
The differences to run() method:
1. The passed function should have additional
argument QPromise<T> &, declared as a first argument.
2. The return value of the function must be void.
Result reporting should be done through
passed QPromise<T> &promise argument.
3. By default, runWithPromise() doesn't support functors
with overloaded operator()().
In case of overloaded functors the user
needs to explicitly specify the result type
as a template parameter passed to runWithPromise,
like:
struct Functor {
void operator()(QPromise<int> &) { }
void operator()(QPromise<double> &) { }
};
Functor f;
runWithPromise<double>(f); // this will select the 2nd overload
Task-number: QTBUG-84702
Change-Id: Ie40d466938d316fc46eb7690e6ae0ce1c6c6d649
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r-- | src/corelib/thread/qpromise.h | 1 | ||||
-rw-r--r-- | src/corelib/thread/qpromise.qdoc | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/thread/qpromise.h b/src/corelib/thread/qpromise.h index 32aaa202f5..59c31de212 100644 --- a/src/corelib/thread/qpromise.h +++ b/src/corelib/thread/qpromise.h @@ -63,6 +63,7 @@ public: { other.d = QFutureInterface<T>(); } + QPromise(QFutureInterface<T> &other) : d(other) {} QPromise& operator=(QPromise<T> &&other) { QPromise<T> tmp(std::move(other)); diff --git a/src/corelib/thread/qpromise.qdoc b/src/corelib/thread/qpromise.qdoc index b404732a9e..9c7925da95 100644 --- a/src/corelib/thread/qpromise.qdoc +++ b/src/corelib/thread/qpromise.qdoc @@ -78,6 +78,16 @@ \sa operator=() */ +/*! \fn template <typename T> QPromise<T>::QPromise(QFutureInterface<T> &other) + + \internal + Constructs a QPromise with a passed QFutureInterface \a other. + Used internally for QtConcurrent::runWithPromise. + + \sa operator=() +*/ + + /*! \fn template <typename T> QPromise<T> &QPromise<T>::operator=(QPromise<T> &&other) Move assigns \a other to this promise and returns a reference to this |