Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Concurrent Map Use of Member Functions
QtWS25 Last Chance

Qt Concurrent Map Use of Member Functions

Scheduled Pinned Locked Moved Unsolved General and Desktop
multithreadqtconcurrent
2 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RB_White
    wrote on 31 May 2016, 20:26 last edited by
    #1

    Hello I am trying to run class method in QtConcurrent::map, pas a QStringList for iteration.

    This is how I use the QtConcurrent:

    void worker::start()
    {
        set_Fl_Name("main");
        set_Root_Path("/home/rober");
        QStringList temp;
        QDir dr(root_path);
        //QStringList temp;
        foreach(QFileInfo fl,dr.entryInfoList(QDir::NoDotAndDotDot|QDir::Dirs))
        {
            temp.append(fl.filePath());
        }
        temp.append(root_path);
        QtConcurrent::map(temp,&worker::search_rec);
    }
    

    And this is the definition of the method I am trying to call:

        QStringList search_rec(QString str);
    

    But It doesn't work, and i t gives me this kind of error message:

    /usr/include/qt5/QtConcurrent/qtconcurrentmapkernel.h:71: error: no match for call to '(QtConcurrent::MemberFunctionWrapper1<QStringList, worker, QString>) (QString&)'
    map(*it);

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 31 May 2016, 20:50 last edited by Chris Kawa
      #2

      Hi, welcome to the forum.

      Couple of things wrong here.

      First, to be able to pass a method like this it needs to be static, otherwise there's no instance to run it on.
      Second, to save you from unnecessary copies it should take the string as a const reference, not by value.
      Third, similar to above, to save yourself from copies where not needed you should use a const reference in the foreach variable declaration.
      Next, The return type of the function you pass should be the type of the element of the container, not the container itself i.e. QString in this case.
      And last but not least - the call to map() is not blocking, so it will return immediately and the function will exit. You passed a local string list to it so it means the asynchronous calls will operate on freed memory and most likely crash. If you want to wait for the results you should rather use blockingMap() instead and if not then you need to store that string list somewhere for the whole duration of the map() execution.

      1 Reply Last reply
      0

      1/2

      31 May 2016, 20:26

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved