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. Does Qt has an equivalent of C# parallel.foreach?

Does Qt has an equivalent of C# parallel.foreach?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.6k 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.
  • D Offline
    D Offline
    Dr. No
    wrote on 16 Jul 2018, 18:06 last edited by
    #1

    C# has a very easy way to run a block in parallel, like this:

    Parallel.ForEach(arr, item =>
    {
         doSomethingWith(item);
    });
    

    C#'s doc: https://msdn.microsoft.com/en-us/library/system.threading.tasks.parallel.foreach(v=vs.110).aspx

    Is there an equivalente in Qt?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 16 Jul 2018, 20:13 last edited by
      #2

      Hi,

      You are likely looking for the QtConcurrent module.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • D Offline
        D Offline
        Dr. No
        wrote on 17 Jul 2018, 14:18 last edited by
        #3

        I just found omp header in Qt:

        #pragma omp parallel for
        for(int i = 1; i < size; ++i) {
          // ...
        }
        
        1 Reply Last reply
        0
        • V Offline
          V Offline
          VRonin
          wrote on 17 Jul 2018, 15:54 last edited by VRonin
          #4

          Use QtConcurrent::blockingMapped(std::begin(arr),std::end(arr),doSomethingWith) or std::for_each(std::execution::par,std::begin(arr),std::end(arr),doSomethingWith) (C++17 onward)

          "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

          1 Reply Last reply
          3

          3/4

          17 Jul 2018, 14:18

          • Login

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