Qt World Summit: Submit your Presentation

Cannot open include file: 'QApplication' after including core, gui, & widgets in pro file

  • Hello folks,

    I'm reverse engineering an example Qt widgets application from scratch. I'm using the Console application in QtCreator as a template so I have minimal boiler plate code to work with.

    I have written a widgets application but I am getting the dreaded:

    Cannot open include file: 'QApplication': No such file or directory

    Error and for the life of me, I cannot figure out what is wrong. The .Pro file should tell the compiler what libraries it needs, right? I've added:

    QT       += core gui widgets 

    To my .pro file and I am still getting this error. My widgets source application does not get this error. At this point, the code between the two applications are virtually identical, but the application I wrote from the Console template refuses to compile. Its as if the qmake isn't even running when I hit the compile button.

    What on earth am I doing wrong here?

  • I seem to have located the problem - the .pro file isn't being used or parsed at all. I'm not sure how the initial console application was working in the first place.

    Is something fundamentally broken with the Console template application in QtCreator? I'm not even sure how to fix this.

  • I went ahead and reproduced this apparent bug with a standard Console template. My .pro file looks like this:

    QT += widgets
    SOURCES += \

    My main.cpp file looks like this:

    #include <QApplication>
    int main(int argc, char *argv[])
        QApplication app(argc, argv);
        return app.exec();

    Even though I am using widgets in my .pro file, I am still getting the error.

  • Lifetime Qt Champion

    Do you use the plain c++ console template or
    the qt console template ?

  • Did you re-run qmake ?
    Any change to a .pro file should be accompanied by a clean, run qmake, rebuild.

  • @mrjj I'm using the Qt Console Application from the QtCreator new project wizard.

    @mranger90 qmake is run when the project is build, no? I've tried a clean re-build and it doesn't seem to matter - the .pro file is simply not being evaluated.

    It is worth pointing out that I tried this code again using the Qt Widgets Application template from the QtCreator wizard and it worked out of the box. Something is up with the Qt Console Application template.

    I'm aware that by definition, the Qt Console Application is not designed to do anything GUI related, however this behavior is more than a little odd.

  • Actually, no. QMake is not necessarily run as part of build or rebuild or rebuild-all.
    You should specifically hit the "build | Run qmake" menu item in QtCreator.
    To verify, check the timestamps on Makefile.Debug and Makefile.Release in the build folders.

Log in to reply