[Development] QFutureInterface

Marc Mutz marc.mutz at kdab.com
Fri Dec 4 10:18:08 CET 2015

On Friday 27 November 2015 13:45:28 Bauer, Christian wrote:
> Hi Marc,
> > You should be able to develop a QPromise/QPackagedTask with the current
> > QFutureInterface already. At least as long as it's attached to some >
> > QThreadPool.
> > What, exactly, are you trying to do that requires a patch to QFI?
> I am not aware of any QPackagedTask in Qt, only of packaged_task in C++11.
> Or do you mean RunFunctionTaskBase?

I said "you can develop one", not that there _is_ one already :)

> Our (simplified) problem is: this function does not return a value but
> feeds an asynchronous pipeline. When the pipeline processing is done it
> will call promise.SetResult(); promise.reportResult();
> and only then the future should be notified of the result.

1. Inherit your runnable from QRunnable and QFutureInterface<T>
    In the ctor, call QFI::setRunnable(this).
2. Create an instance of your runnable, call runnable.future() to get the
    QFuture end
3. Schedule the runnable on a thread pool (cf. QConcurrent::run(QThreadPool*
    for how to implant that into the QFutureInterface so work stealing works).
4. From within runnable::run() operate the QFutureInterface API
5. Use the QFuture obtained in (2) as you'd use an other future.

> We can achieve this by using a custom waitForFinished() in our future
> wrapper, instead of using the QFuture waitForFinished. But this requires
> access to the QWaitCondition of the QFutureInterface.

Don't understand this, but maybe I don't need to. Just tell me where your use-
case fails in the recipe above.


Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts

More information about the Development mailing list