2017-10-08 81 views
0

我寫了自己的合併排序,在一個線程中工作正常,但是當我嘗試以並行方式運行時,出現錯誤。QT並行編程

void GameModel::mergesort_mt3(QVector<QPair<int,Matrix>>::iterator begin, 
          QVector<QPair<int,Matrix>>::iterator end, 
       unsigned int N) 
{ 
auto len = std::distance(begin, end); 
if (len <= 1024 || N < 2) 
{ 
    std::sort(begin,end); 
    return; 
} 
QVector<QPair<int,Matrix>>::iterator mid = std::next(begin, len/2); 
//auto fn = QtConcurrent::run(mergesort_mt3, begin, mid, N-2); 
mergesort_mt3(begin, mid, N-2); 
mergesort_mt3(mid, end, N-2); 
//fn.waitForFinished(); 
std::inplace_merge(begin, mid, end); 
} 

當我使用註釋的代碼我得到這個錯誤:

error: no matching function for call to 'run(<unresolved overloaded function 
type>, QPair<int, QPair<QVector<QVector<int> >, int> >*&, QPair<int, 
QPair<QVector<QVector<int> >, int> >*&, unsigned int)' 
auto fn = QtConcurrent::run(mergesort_mt3, begin, mid, N-2); 
                  ^
In file included from 
C:/Qt/5.9.1/mingw53_32/include/QtConcurrent/QtConcurrent:14:0, 
      from ..\Game15\model.cpp:2: 
note: 
candidate: template<class T> QFuture<T> QtConcurrent::run(T (*)()) 
QFuture<T> run(T (*functionPointer)()) 

任何想法,我做錯了什麼?

回答

1

這應該是這樣的

auto fn = QtConcurrent::run(this, GameModel::mergesort_mt3, begin, mid, N-2); 

Qt成員函數。