PDA

View Full Version : How to pass an std::vector to QtConcurrent::run ?



marko
20th August 2011, 11:46
Hi all
While creating my QT App I have encountered a problem with passing std::vector to QtConcurrent::run.
Basically I have this funtion:

void g(int bloki, int min, int max, float krok, vector<double> &qam_signal, vector<double> &qam_szum)

I try to run it in a seperate thread to make my GUI responsive when some calculations are made, I do it with:

*obliczenia = QtConcurrent::run(g, bloki, min, max, krok, qam_signal, qam_szum);
sprawdzenie->setFuture(*obliczenia);

I am sure that the method of calling the function is correct. When I delete vectors from my function, there is no problem.
With vectors I get the following error:

error: no matching function for call to 'run(void (&)(int, int, int, float, QVector<double>&, QVector<double>&), int&, int&, int&, int&, std::vector<double, std::allocator<double> >&, std::vector<double, std::allocator<double> >&)'

I have no idea why the vectors cannot be passed to the function

Thanks
Marek

wysota
20th August 2011, 12:22
Is there any specific reason why you are using std::vector instead of QVector or QList? It seems your variables are of type QVector and not std::vector.

marko
20th August 2011, 13:20
I use std::vector just because I got used to it. I have changed my function to use std::vector, but there is no difference in regard to the error:

no matching function for call to 'run(void (&)(int, int, int, float, std::vector<double, std::allocator<double> >, std::vector<double, std::allocator<double> >), int&, int&, int&, int&, std::vector<double, std::allocator<double> >&, std::vector<double, std::allocator<double> >&)'

I have also tried this with QVector and the function doesn't work either

wysota
20th August 2011, 14:29
Does it change anything if you replace references to those vectors with const references (just change the function signature)?

Edit: aaa... I think I remember. run() can accept a function with at most five arguments. Yours has six.