5

我创建了一个 QFuture,我想用它来并行化对成员函数的调用。更准确地说,我有一个类 solveParallel 与 .h :

class solverParallel {
public:
  solverParallelData(Manager* mgr_);
  virtual ~solverParallel(void);

  void runCompute(solveModel * model_);

  bool resultComput();

private:
  Manager *myMgr;
  QFuture<bool> myFutureCompute;
}; 

其中方法 runCompute() 正在创建 myFutureCompute 成员。.cpp 看起来像

solveParallel::solveParallel(Manager* mgr_)
:m_mgr(mgr_)
{
}

solverParallel::~solverParallel(void){}

void solverParallel::runCompute(solveModel* model)
{
  futureComput = QtConcurrent::run(&this->myMgr,&Manager::compute(model));
}

bool solverParallelData::resultComput()
{
  return m_futureComput.result();
}

包括(S)是好的。编译失败,在线

futureComput = QtConcurrent::run(&this->myMgr,&Manager::compute(model));

出现此错误:

Error   44  error C2784: 'QFuture<T> QtConcurrent::run(T (__cdecl *)(Param1),const     Arg1 &)' : could not deduce template argument for 'T (__cdecl *)    (Param1)' from 'Manager **'   solverparallel.cpp 31

此外,在同一行代码中“&Manager”的鼠标信息代表:错误:非静态成员引用必须相对于特定对象。

你知道诀窍在哪里吗?谢谢并恭祝安康。

4

1 回答 1

14

官方文档

QtConcurrent::run() 也接受指向成员函数的指针。第一个参数必须是 const 引用或指向类实例的指针。调用 const 成员函数时,通过 const 引用传递很有用;通过指针传递对于调用修改实例的非常量成员函数很有用。

您正在将指针传递给指针。另请注意,您不能以您的方式传递参数,而是作为函数中的额外参数run。以下应该有效:

futureComput = QtConcurrent::run(this->myMgr,&Manager::compute, model);
于 2012-04-03T15:24:44.510 回答