Commit 300c48e8 authored by Erik Verbruggen's avatar Erik Verbruggen

Utils: bring QtConcurrent::run into the current century.

.. by adding support to pass in a std::function (which includes lambdas)
as the function to run. The run function only takes functors that have
a QFutureInterface& as parameter, because a lambda can already capture
anything that would be passed in on invocation. Parameter-less
std::function<>s are already handled by QtConcurrent (in Qt).

To use it, you'll have to explicitly set the template parameter T on the

Change-Id: Ie145fc3245d59fdea9d4703dab155ce9100eff89
Reviewed-by: default avatarDaniel Teske <>
parent 847f10e9
......@@ -31,9 +31,12 @@
#include <qrunnable.h>
#include <qfuture.h>
#include <qfutureinterface.h>
#include <qthreadpool.h>
#include <functional>
namespace QtConcurrent {
......@@ -42,7 +45,7 @@ template <typename T, typename FunctionPointer>
class StoredInterfaceFunctionCall0 : public QRunnable
StoredInterfaceFunctionCall0(void (fn)(QFutureInterface<T> &))
StoredInterfaceFunctionCall0(const FunctionPointer &fn)
: fn(fn) { }
QFuture<T> start()
......@@ -416,6 +419,13 @@ QFuture<T> run(void (Class::*fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4,
return (new StoredInterfaceMemberFunctionCall5<T, void (Class::*)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4, Arg5), Class, Arg1, Arg2, Arg3, Arg4, Arg5>(fn, object, arg1, arg2, arg3, arg4, arg5))->start();
template <typename T>
QFuture<T> run(const std::function<void (QFutureInterface<T> &)> &fn)
return (new StoredInterfaceFunctionCall0<T, std::function<void (QFutureInterface<T>)>>(fn))->start();
} // namespace QtConcurrent
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment