2013-06-04 48 views
5

将具有6个参数或更多参数的函数传递给QtConcurrent::run()时出现编译错误。当我将它们减少到5个参数时,我不会再遇到这个错误。QtConcurrent :: run()不能处理超过5个参数?

这个虚拟的代码重现错误对我来说:

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

} 

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

编译器错误是:

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

难道这应该是这样的吗?最多是否限制了5个参数QtConcurrent::run()

+2

如果它有限,它不会让我感到惊讶。毕竟,它必须与预C++ 11编译器一起工作。 – Angew

回答

8

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); 

有5个参数是函数可以

6

在一边,你可以使用std::bindboost::bind传递更多然后5个参数(如果无限的C++ 11):

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

另一方面,5个参数守对于每个功能来说足够的是。您可能需要重新考虑您的设计以减少功能参数的数量。你可以传递一些对象来代替。

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

也不要忘记在预5.3,没有理由并发::运行可以hung有时构建。

相关问题