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. QtConcurrent (map, mapped) without c++11

QtConcurrent (map, mapped) without c++11

Scheduled Pinned Locked Moved General and Desktop
qtconcurrentc++11
2 Posts 2 Posters 2.0k 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.
  • shaveraS Offline
    shaveraS Offline
    shavera
    wrote on last edited by shavera
    #1

    So far, in order to implement QtConcurrent::map, and QtConcurrent::mapped, I've had to use lambdas or std::function objects. It's working okay, but it seems a bit strange when so much of Qt is indifferent to c++11 at best (one can argue it bumps a little against the standard here and there)

    examples:

    {
    // in some class, making use of its member variables m_bar
    QList<double> fooList {.. initialized ..};
    auto future QtConcurrent::map(fooList, [this](double& foo){
        foo = this->doStuff(m_bar, foo);
    });
    }
    

    in the mapped case, it couldn't detect a return_type for the lambda, so one could wrap a lambda in a std::function or bind it directly

    {
    QList<double> fooList{};
    
    using std::placeholders::_1;
    auto calc_F = std::bind(&MyClass::doStuff, this, _1);
    
    auto future = QtConcurrent(fooList, calc_F);
    }
    

    I'd suggest adding these kind of constructions into the documentation, given their utility.

    But what other ways might one use member functions within QtConcurrent? The examples provided make use of global functions which are a little trivial to extend.

    JKSHJ 1 Reply Last reply
    0
    • shaveraS shavera

      So far, in order to implement QtConcurrent::map, and QtConcurrent::mapped, I've had to use lambdas or std::function objects. It's working okay, but it seems a bit strange when so much of Qt is indifferent to c++11 at best (one can argue it bumps a little against the standard here and there)

      examples:

      {
      // in some class, making use of its member variables m_bar
      QList<double> fooList {.. initialized ..};
      auto future QtConcurrent::map(fooList, [this](double& foo){
          foo = this->doStuff(m_bar, foo);
      });
      }
      

      in the mapped case, it couldn't detect a return_type for the lambda, so one could wrap a lambda in a std::function or bind it directly

      {
      QList<double> fooList{};
      
      using std::placeholders::_1;
      auto calc_F = std::bind(&MyClass::doStuff, this, _1);
      
      auto future = QtConcurrent(fooList, calc_F);
      }
      

      I'd suggest adding these kind of constructions into the documentation, given their utility.

      But what other ways might one use member functions within QtConcurrent? The examples provided make use of global functions which are a little trivial to extend.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @shavera said:

      I'd suggest adding these kind of constructions into the documentation, given their utility.

      They are :-) Scroll to the bottom of http://doc.qt.io/qt-5/qtconcurrentmap.html

      But what other ways might one use member functions within QtConcurrent? The examples provided make use of global functions which are a little trivial to extend.

      See the same link

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      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