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

Build errors in tutorial sample project



  • I followed steps in tutorial: https://wiki.qt.io/Qt_for_Beginners
    I built the first project (File --> New File or Project --> Other projects --> Empty QMake Project --> ...) I created a source file main.cpp as indicated in the tutorial.
    main.cpp:
    #include <QApplication>
    #include <QPushButton>

    int main(int argc, char **argv)
    {
    QApplication app (argc, argv);

    QPushButton button ("Hello world !");
    button.show();

    return app.exec();
    }

    1. I tried to build it and I got compilation errors: QApplication: file not found
      QPushButton: file not found
      .....
    2. I opened the project file and found only lines of:

    SOURCES +=
    main.cpp

    Not as in tutorial:

    TEMPLATE = app
    TARGET = name_of_the_app

    QT = core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    SOURCES += main.cpp

    How come?


  • Lifetime Qt Champion

    Hi,

    The tutorial says:
    In a project file, there is some minimal code that should always be written :

    TEMPLATE = app
    TARGET = name_of_the_app
    
    QT = core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    

    Which means that you have to add it to your project because as the name of the template suggests, it's an empty project to get you started.



  • I modified project file as you said and it works then. Thanks.


Log in to reply