Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't qmake add "QT += widgets" to *.pro files automatically?

Tags:

qt

I am trying to build a simple "Hello World" example in QT5.

I am compiling the code using the below steps

qmake-qt5 -project
qmake-qt5
make

I am getting the below error

main.cpp:1:24: fatal error: QApplication: No such file or directory
 #include <QApplication>
                        ^
compilation terminated.

When I read QT forums, its mentioned to add "QT += widgets" to the *.pro file. After doing this the code is compiled.

Question: Why do I need to add "QT += widgets" to the *.pro file manually ? Why doesn't qmake do it automatically ?

Note: I am using Ubuntu

Code

#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel *label = new QLabel("Hello Qt!");
    label->show();
    return app.exec();
} 
like image 337
robomon Avatar asked Sep 27 '22 14:09

robomon


1 Answers

The QT variable in the .pro file is used to specify the modules which are used in the project. And as the qmake manual mentions:

By default, QT contains both core and gui, ensuring that standard GUI applications can be built without further configuration.

The Qt Widgets module is not linked by default and has thus to be specified in the .pro file with QT += widgets.

like image 128
agold Avatar answered Sep 29 '22 05:09

agold