2012-04-03 52 views
5

我創建了一個QFuture,我想用它來並行調用成員函數。更確切地說,我有一個類solveParallel與.H:Qt與成員函數併發

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

包括所有權利。編譯失敗,上線

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 

另外,關於在同一行的代碼「&經理」鼠標信息表示:錯誤:一個非靜態成員引用必須是相到一個特定的對象。

你看到訣竅在哪裏?感謝致敬。

回答

14

official documentation

QtConcurrent::run() also accepts pointers to member functions. The first argument must be either a const reference or a pointer to an instance of the class. Passing by const reference is useful when calling const member functions; passing by pointer is useful for calling non-const member functions that modify the instance.

您possing一個指針的指針。還要注意,你不能像你那樣傳遞參數,而是作爲run函數中的額外參數。以下應該工作:

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