Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QtConcurrent compile errors



  • Hi,
    I am a new to Qt and first time usng QtConcurrent and getting lots of errors:(
    I have done the "QT += concurrent" in the .pro file.
    I also tried a func param and still similar errors.

    Any clues?
    Thanks!

    void Floor::upPressed(){
    ...
    FlrReq flrReq(flr, true);
    QFuture<int> future = QtConcurrent::run(this, &Floor::runFloorRequest, flrReq);

    int res = future.result();
    

    }

    int Floor::runFloorRequest(FlrReq req)
    {
    std::cout << "flrNum: " << req.getFloorNum() << " dir:" << req.getDir();
    return 0;
    }

    In file included from C:/Qt/6.2.0/mingw81_64/include/QtCore/qfuture.h:48,
    from C:/Qt/6.2.0/mingw81_64/include/QtCore/qcoreapplication.h:49,
    from C:/Qt/6.2.0/mingw81_64/include/QtCore/qcommandlineparser.h:45,
    from C:/Qt/6.2.0/mingw81_64/include/QtCore/QtCore:54,
    from C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/QtConcurrentDepends:3,
    from C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/QtConcurrent:3,
    from ..\Comp3004A2\floor.h:11,
    from ..\Comp3004A2\floor.cpp:1:
    C:/Qt/6.2.0/mingw81_64/include/QtCore/qfuture_impl.h: In instantiation of 'struct QtPrivate::ArgResolver<Floor*>':
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:224:1: required from 'struct QtConcurrent::PromiseTaskResolver<Floor*, int (Floor::)(FlrReq), FlrReq>'
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:247:8: required from 'struct QtConcurrent::TaskResolverHelper<std::integral_constant<bool, false>, Floor
    , int (Floor::)(FlrReq), FlrReq>'
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:253:8: required from 'struct QtConcurrent::TaskResolver<Floor
    , int (Floor::)(FlrReq), FlrReq>'
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentrun.h:82:76: required from 'auto QtConcurrent::run(QThreadPool
    , Function&&, Args&& ...) [with Function = Floor*; Args = {int (Floor::)(FlrReq), FlrReq&}]'
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentrun.h:99:15: required from 'auto QtConcurrent::run(Function&&, Args&& ...) [with Function = Floor
    ; Args = {int (Floor::)(FlrReq), FlrReq&}]'
    ..\Comp3004A2\floor.cpp:93:82: required from here
    C:/Qt/6.2.0/mingw81_64/include/QtCore/qfuture_impl.h:168:43: error: 'operator()' is not a member of 'std::decay<Floor
    >::type' {aka 'Floor*'}
    struct ArgResolver : ArgResolver<decltype(&std::decay_t<F>::operator())>
    ^~~~
    In file included from C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtaskbuilder.h:45,
    from C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/QtConcurrent:4,
    from ..\Comp3004A2\floor.h:11,
    from ..\Comp3004A2\floor.cpp:1:
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h: In instantiation of 'struct QtConcurrent::PromiseTaskResolver<Floor*, int (Floor::)(FlrReq), FlrReq>':
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:247:8: required from 'struct QtConcurrent::TaskResolverHelper<std::integral_constant<bool, false>, Floor
    , int (Floor::)(FlrReq), FlrReq>'
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:253:8: required from 'struct QtConcurrent::TaskResolver<Floor
    , int (Floor::)(FlrReq), FlrReq>'
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentrun.h:82:76: required from 'auto QtConcurrent::run(QThreadPool
    , Function&&, Args&& ...) [with Function = Floor*; Args = {int (Floor::)(FlrReq), FlrReq&}]'
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentrun.h:99:15: required from 'auto QtConcurrent::run(Function&&, Args&& ...) [with Function = Floor
    ; Args = {int (Floor::)(FlrReq), FlrReq&}]'
    ..\Comp3004A2\floor.cpp:93:82: required from here
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:224:1: error: no type named 'IsPromise' in 'struct QtPrivate::ArgResolver<Floor
    >'
    {
    ^
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h: In instantiation of 'static auto QtConcurrent::PromiseTaskResolver<Function, Args ...>::run(QtConcurrent::PromiseTaskResolver<Function, Args ...>::TaskWithArgs&&, const QtConcurrent::TaskStartParameters&) [with Function = Floor*; Args = {int (Floor::)(FlrReq), FlrReq}; QtConcurrent::PromiseTaskResolver<Function, Args ...>::TaskWithArgs = std::tuple<Floor, int (Floor::)(FlrReq), FlrReq>; typename std::decay<_Tp>::type = Floor]':
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentrun.h:82:76: required from 'auto QtConcurrent::run(QThreadPool*, Function&&, Args&& ...) [with Function = Floor*; Args = {int (Floor::)(FlrReq), FlrReq&}]'
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentrun.h:99:15: required from 'auto QtConcurrent::run(Function&&, Args&& ...) [with Function = Floor
    ; Args = {int (Floor::)(FlrReq), FlrReq&}]'
    ..\Comp3004A2\floor.cpp:93:82: required from here
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:231:83: error: no type named 'PromiseType' in 'struct QtPrivate::ArgResolver<Floor
    >'
    using PromiseType = typename QtPrivate::ArgResolver<Function>::PromiseType;
    ^
    C:/Qt/6.2.0/mingw81_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:232:17: error: no type named 'PromiseType' in 'struct QtPrivate::ArgResolver<Floor*>'
    return (new StoredFunctionCallWithPromise<Function, PromiseType, Args...>(std::move(args)))
    ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ..\Comp3004A2\floor.cpp: In member function 'void Floor::upPressed()':
    ..\Comp3004A2\floor.cpp:93:44: error: conversion from 'void' to non-scalar type 'QFuture<int>' requested
    QFuture<int> future = QtConcurrent::run(this, &Floor::runFloorRequest, flrReq);
    ~^~~~~~~~~~~~~~~~~~~~~~~


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    QtConcurent run is usually not called on an instance of the object you want to apply run on.

    Another issue here is that the way you use it makes the call to run overkill since you are directly waiting for the result and thus blocking the execution.



  • @mehr said in QtConcurrent compile errors:

    QFuture<int> future = QtConcurrent::run(this, &Floor::runFloorRequest, flrReq);

    In Qt 6 this should be:

    QFuture<int> future = QtConcurrent::run(&Floor::runFloorRequest, this, flrReq);
    


  • @SGaist Thanks!
    Actually the solution posted by Jonas below fixed it.


Log in to reply