Qt World Summit: Register Today!

Unable to understand QtConcurrent syntax

  • 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.

  • Lifetime Qt Champion

    @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.

Log in to reply