Compilation error - 'QFuture' is not declared in this scope - Qt

  • Hello there,

    I am trying to use QFuture and QtConcurrent classes in my application. I # included <QFuture> like this:


    but when i compiled, got a compilation error. I could not event # include QtConcurrent.

    Do I need to include something else in my .pro file to use both of these?


  • Moderators

    It should work. Did you use some special custom configure flags (if you have compiled Qt yourself)?

  • No nothing of that sort. Yeah, its strange. I am using Qt version 4.7.3 on QtCreator.

    I just want to try something like

    @void myclass::fun()

    void myclass::init()
    QFuture<void> future = QtConcurrent::run(fun);

    therefore i want to include QFuture which documentation says should be found in @QtCore@ . Even after including QFuture, I am getting compilation error. QtConcurrent is not even getting included.

    Please let me know if there is some issue with this.

  • Moderators

    I've never used that class. Here is what stackoverflow has to say on this: "link":

    #include <QFuture>
    #include <QtConcurrent/QtConcurrentRun>

  • Thanks for putting a search but doesn't work for me. Can you please try creating a hello world app and use these?

  • [quote author="raj.qtdev" date="1382959691"]Thanks for putting a search but doesn't work for me. [/quote]

    What exactly didn't work for you ? The compiler don't find the QFuture header or other linker error ? What sierdzio said is correct, so you should be fine including QFuture in that way. From what I see you try to run a class member function, in this case you need something like this:
    QFuture<void> future = QtConcurrent::run(this, &myclass::run)

  • That is okay @cincirin. The compiler didn't find the QFuture header and the QtConcurrent header that is the main issue. Should be simple thing but don't know what is missing apart from #including the two headers

  • Moderators

    Perhaps you forgot to include this in your .pro file, but that is unlikely:
    QT += core

    Since you have posted it in Mobile and Embedded, let me ask you this: even though you have not compiled Qt yourself, maybe you are aware of some special conditions your platform may be forcing? Maybe threading support is somehow throttled on that hardware?

  • Ok, I simply included the two files in this way:
    #include <QFuture>
    #include <QtConcurrentRun>

    The project is successfully compiled even with Qt 4.5.3 on both Mac and Windows.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.