sashoalm
sashoalm

Reputation: 79685

QtConcurrent::run() can't handle more than 5 arguments?

I'm getting a compile error when passing a function with 6 parameters or more to QtConcurrent::run(). When I reduce them to 5 parameters, I no longer get this error.

This dummy code reproduces the error for me:

void foo(int, int, int, int, int, int)
{

}

QtConcurrent::run(foo, 1, 2, 3, 4, 5, 6);

The compiler error is:

error: no matching function for call to 'run(void (&)(int, int, int, int, int, int), int, int, int, int, int, int)'

Is this supposed to be so? Is QtConcurrent::run() really limited to 5 arguments at most?

Upvotes: 6

Views: 4395

Answers (2)

Lol4t0
Lol4t0

Reputation: 12557

On the one side, you can use std::bind or boost::bind to pass more then 5 arguments (unlimited in case of C++11):

QFuture<void> result = QtConcurrent::run(std::bind(&foo, 1, 2, 3, 4, 5, 6));

On the other side, 5 arguments should be enough for every function. You may want reconsider your design to decrease the number of function parameters. You can pass some object to function instead.

Data d;
QFuture<void> result = QtConcurrent::run(foo, d);

Also don't forget that Concurrent::run can hung sometimes with no reason in pre-5.3 builds.

Upvotes: 7

grisha
grisha

Reputation: 1297

See qtconcurrentrun.h

template <typename T, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5>
QFuture<T> run(T (*functionPointer)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5);

There are 5 arguments that function can take

Upvotes: 9

Related Questions