Results 1 to 4 of 4

Thread: How to pass an std::vector to QtConcurrent::run ?

  1. #1
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default How to pass an std::vector to QtConcurrent::run ?

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to pass an std::vector to QtConcurrent::run ?

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to pass an std::vector to QtConcurrent::run ?

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to pass an std::vector to QtConcurrent::run ?

    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.
    Last edited by wysota; 20th August 2011 at 14:39.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 2nd July 2011, 01:02
  2. qtconcurrent
    By knishaq in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2009, 08:41
  3. vector of vector and computes
    By mickey in forum General Programming
    Replies: 1
    Last Post: 15th May 2008, 12:47
  4. insert in a vector of vector
    By mickey in forum General Programming
    Replies: 3
    Last Post: 6th March 2007, 08:45
  5. vector of vector size
    By mickey in forum General Programming
    Replies: 5
    Last Post: 13th February 2007, 15:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.