我真的試圖將我知道的所有東西結合起來,以使其工作。我相信當前結構中的死鎖或其他線程問題沒有問題。但是,有些部分丟失了,可用的文檔沒有幫助我(我在C++文檔中沒有經驗)。如何映射QVector的QList上的QtConcurrent <double>並將其縮小爲一個QVector
int main()
{
QVector<double> vector_of_doubles(5);
qFill(vector_of_doubles.begin(), vector_of_doubles.end(), 1);
QList< QVector<double> > list_of_vectors;
list_of_vectors.append(vector_of_doubles);
list_of_vectors.append(vector_of_doubles);
list_of_vectors.append(vector_of_doubles);
QFuture< QVector<double> > res;
res = QtConcurrent::mappedReduced(list_of_vectors, Map(), Reduce());
res.waitForFinished();
qDebug()<<res.result();
return 0
}
QVector<double> Reduce(QVector<double> vector)
// Here the vectors get combined into one big vector....but how?
{
....
return big_vector;
}
QVector<double> Map(QVector<double> vector)
{
for (int i = 0; i < vector.size(); i++)
{
vector[i] = vector[i] + i;
}
return vector;
}
從保持的QList 3個矢量全部爲一輸入,我想去到一個載體中,爲此,每一個矢量增添一些迭代變量。 我希望爲qDebug()
結果看:
{1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4 ,5}
這裏我認爲是缺失的部分:
- 有關
QtConcurrent:mappedReduced()
,我在給什麼正確的參數? - 函數返回如何,這些應該如何解決?
- 究竟需要包含什麼,我只需要包含QtConcurrent?
- 一旦這個開始工作,並且列表將是巨大的,據我瞭解QtConcurrent將執行線程管理(使用可用的核心),並且列表中的所有項目(即使不是相同的大小)將被傳遞巧妙地對線程不要讓他們閒置?
編輯(也許這是它發生在一個按鈕有問題點擊):
雖然工作爲我的例子,什麼都可以錯了,當我使用這個:
扼流圈:res = QtConcurrent::mappedReduced(holder, correlate, Reduce, QtConcurrent::SequentialReduce);
VAR:QList< QVector<double> > holder;
功能涉及:
QVector<double> correlate(QVector<double> &var1);
和
void Reduce(QVector<double> &reduceResult, const QVector<double> &partial)`
錯誤:沒有匹配函數調用'mappedReduced(QList<QVector<double> >&, <unresolved overloaded function type>, <unresolved overloaded function type>, QtConcurrent::ReduceOption)'
而且還:「無法推斷出模板參數與resultType」
這是同樣的事情作爲工作的事控制檯應用程序。
其中doSomeMapping是我的映射函數,joinVectors是reduce函數,什麼是最後一個參數? – PascalVKooten
啊在文檔中發現了它。我相信我甚至可以使用無序的減少。這個論點是必要的嗎?它似乎經常被忽略。 – PascalVKooten
另外,一切似乎設置正確,但我得到'/usr/include/qt5/QtConcurrent/qtconcurrentmapkernel.h:96:錯誤:未定義的引用'QtConcurrent :: ThreadEngineBase ::〜ThreadEngineBase()'' – PascalVKooten