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. Proper use of QtConcurrent::map / mapped
Qt 6.11 is out! See what's new in the release blog

Proper use of QtConcurrent::map / mapped

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.4k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    SQEW
    wrote on last edited by
    #1

    Hi,

    I would like to make use of QtConcurrent::map to iterate over a QStringList.

    However I'm a bit lost.

    void ThisClass::startScanning()
    {
    QStringList stuff;
    stuff << "hey";
    stuff << "woohah";
    QFuture<void> future=QtConcurrent::map(stuff,&ThisClass::doStuff);
    }

    void ThisClass::doStuff(QString file)
    {
    //do stuff with file
    }

    Compiling this returns the error

    error: no match for call to '(QtConcurrent::MemberFunctionWrapper1<void, ThisClass, QString>) (QString&)'

    I'm fairly new to C++, can anybody help?

    Thanks in advance.

    1 Reply Last reply
    0
    • U Offline
      U Offline
      unai_i
      wrote on last edited by
      #2

      Hi,
      If you refer to "Using Member Functions" section of the "QtConcurrent documentation":http://qt-project.org/doc/qt-4.8/qtconcurrentmap.html .
      It states:
      QtConcurrent::map(), QtConcurrent::mapped(), and QtConcurrent::mappedReduced() accept pointers to member functions. The member function class type must match the type stored in the sequence

      So in your case your QList should contain "ThisClass" instances.
      You can maybe achieve your goal using function objects to wrap your "This class" instance:
      @
      struct WrapperObject
      {
      WrapperObject(ThisClass *instance)
      : m_instance(instance) { }

      typedef void result_type;
      
      void operator()(const QString &string)
      {
           m_instance->doStuff(string);
      }
      
      ThisClass *m_instance;
      

      };

      QStringList stuff;
      stuff << “hey”;
      stuff << “woohah”;
      QFuture<void> future = QtConcurrent::maped(stuff, WrapperObject(pMyInstance));
      

      @

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SQEW
        wrote on last edited by
        #3

        Thanks for your reply, uh, I'm trying to understand what you're doing here, at any rate this won't compile either since the pMyInstance object is not known?

        Isn't there a solution that doesn't rape the elegance of my code? :p

        1 Reply Last reply
        0
        • U Offline
          U Offline
          unai_i
          wrote on last edited by
          #4

          Hi,
          I just took the example of the docs and adapted a little bit to jour example. I will try to think of an alternative solution.

          1 Reply Last reply
          0

          • Login

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