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. Unable to understand QtConcurrent syntax
Qt 6.11 is out! See what's new in the release blog

Unable to understand QtConcurrent syntax

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

    Hello All,

    I'm trying to use QtConcurrent but didn't get it through.

    I'm implementing it for making a function to run in a separate thread. And uses QtCouncurrent because there is the possibility of having 20 to 30k threads in an application, so I found this suitable because it manages threads based on the available cores in CPU.
    I have already tried QThread, QThreadpool and getting some errors, maybe because I'm not managing it properly.

    Please just help me with the following syntax.

    struct datalist
        {
            datalist(QString &file, QStringList &groupList)
                : m_file(file)
                , m_groupList(groupList)
            {}
            QString m_file;
            QStringList m_groupList;
    
        };
    
    typedef QHash<QString, QList<s_DATA>> HashType;
    
    QVector<datalist> dList;
     foreach (QString file, filepaths)
     {
           dList.append(datalist(file, groupList));
     }
    
    foreach (datalist newlist, dList)
     {
                QFuture<HashType> ret = QtConcurrent::run(updateQData, newlist);
            }
    
    HashType updateQData(datalist &dlist)
    {
    HashType gDATA;
    //Some processing here
    return gDATA;
    }
    

    In above I have tried with the map, mapped, reducemapped, but for everytime get same error.

    Here I'm getting many errors as:

    D:\iNnotate\dashboard\settings.h:302: error: C3867: 'Settings::updateQData': non-standard syntax; use '&' to create a pointer to member
    

    Can someone please help me with the syntax of proper use of QtCouncurrent.

    jsulmJ 1 Reply Last reply
    0
    • N npatil15

      Hello All,

      I'm trying to use QtConcurrent but didn't get it through.

      I'm implementing it for making a function to run in a separate thread. And uses QtCouncurrent because there is the possibility of having 20 to 30k threads in an application, so I found this suitable because it manages threads based on the available cores in CPU.
      I have already tried QThread, QThreadpool and getting some errors, maybe because I'm not managing it properly.

      Please just help me with the following syntax.

      struct datalist
          {
              datalist(QString &file, QStringList &groupList)
                  : m_file(file)
                  , m_groupList(groupList)
              {}
              QString m_file;
              QStringList m_groupList;
      
          };
      
      typedef QHash<QString, QList<s_DATA>> HashType;
      
      QVector<datalist> dList;
       foreach (QString file, filepaths)
       {
             dList.append(datalist(file, groupList));
       }
      
      foreach (datalist newlist, dList)
       {
                  QFuture<HashType> ret = QtConcurrent::run(updateQData, newlist);
              }
      
      HashType updateQData(datalist &dlist)
      {
      HashType gDATA;
      //Some processing here
      return gDATA;
      }
      

      In above I have tried with the map, mapped, reducemapped, but for everytime get same error.

      Here I'm getting many errors as:

      D:\iNnotate\dashboard\settings.h:302: error: C3867: 'Settings::updateQData': non-standard syntax; use '&' to create a pointer to member
      

      Can someone please help me with the syntax of proper use of QtCouncurrent.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @npatil15 Read "Using Member Functions" in https://doc.qt.io/qt-5/qtconcurrentrun.html
      You need to call QtConcurrent::run as

      QFuture<HashType> ret = QtConcurrent::run(this, &Settings::updateQData, newlist);
      

      Because updateQData is a method of a class not function.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      4

      • Login

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