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

Not able to use QtConcurrent - Qt



  • Hello,

    I am using Qt-Creator with Qt 4.7.3 for symbian^1.

    I have never been able to successfully compile an application with QtConcurrent/QFutureWatcher APIs. I tried to compile an example program with the current setup but got following compile errors:

    • \QtProjects\qtconcurrentDemo\window.h:38: error: ISO C++ forbids declaration of 'QFuture' with no type
    • \QtProjects\qtconcurrentDemo\window.h:38: error: expected ';' before '<' token
    • \QtProjects\qtconcurrentDemo\window.h:39: error: ISO C++ forbids declaration of 'QFutureWatcher' with no type
    • \QtProjects\qtconcurrentDemo\window.h:39: error: expected ';' before '<' token

    AFAIK I have included everything required to run the program but still getting these errors. I also checked that these APIs were introduced in Qt 4.4 so should not be any issues in that regard.

    Am I missing something to be included in .pro file or something?

    Please let me know if somebody faced similar kinda issue.

    Thanks


  • Moderators

    QFuture is template-based. You need to specify the class like this: QFuture<someClass>.



  • Right, I used it like this.

    @ future = new QFuture<void>;
    watcher = new QFutureWatcher<void>;
    @

    should work isn't it?


  • Moderators

    I think so, yes. I have never used QFuture myself, though.


  • Lifetime Qt Champion

    Hi,

    Indeed, unless you don't care about the return value, the QFuture should match the return type of your function



  • Still not compiling :(

    Well I want to use them to run my db functions in separate threads. Let me know if that is correct approach.


  • Moderators

    [quote author="raj.qtdev" date="1390816157"]
    @ future = new QFuture<void>;
    watcher = new QFutureWatcher<void>;
    @

    should work isn't it?[/quote]Hi,

    You don't create a QFuture manually. You call the QtConcurrent function, and it will return a QFuture for you.

    @
    int myExpensiveFunction();
    ...
    QFuture<int> future = QtConcurrent::run(&myExpensiveFunction);
    @

    See also:

    [quote author="raj.qtdev" date="1390824383"]Well I want to use them to run my db functions in separate threads.[/quote]Are those functions thread-safe?


Log in to reply