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 with different size of return sequence compared to input sequence.
Forum Updated to NodeBB v4.3 + New Features

Qt Concurrent Map with different size of return sequence compared to input sequence.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 282 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.
  • CJhaC Offline
    CJhaC Offline
    CJha
    wrote on last edited by
    #1

    Hi, I am new to QtConcurrent and I am trying to implement a function where I calculate values from a QVector and generate a new one. The problem is the return sequence QtConcurrent::mapped() will not be the same size as the input sequence. The size of the returned sequence depends on the value of the input sequence and the map function (which is a member function and uses a number of member variables to calculate the return sequence) which is operating on it. Is there any way to use QtConcurrent::mapped() with a function that does not have a return value but rather updates the QFuture object itself (or some other kind of hack to achieve a similar result, like combining QtConcurrent::filtered() and QtConcurrent::mapped())?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      If your compiler supports C++17 you can do it using STL instead:

      QVector<int> input {1,2,3,4,5,6,7,8,9};
      QVector<int> output;
      std::mutex outputMutex;
      std::for_each(std::execution::par,input.cbegin(),input.cend(),[&output,&outputMutex](int val){if(val%2) return;  outputMutex.lock(); output << val*2;  outputMutex.unlock();});
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      CJhaC 1 Reply Last reply
      3
      • VRoninV VRonin

        If your compiler supports C++17 you can do it using STL instead:

        QVector<int> input {1,2,3,4,5,6,7,8,9};
        QVector<int> output;
        std::mutex outputMutex;
        std::for_each(std::execution::par,input.cbegin(),input.cend(),[&output,&outputMutex](int val){if(val%2) return;  outputMutex.lock(); output << val*2;  outputMutex.unlock();});
        
        CJhaC Offline
        CJhaC Offline
        CJha
        wrote on last edited by
        #3

        @VRonin Thanks! Yes, my compiler supports C++17, I will try this method.

        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