Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Qtwidgets with Qmake

I am building my Qt Application with qmake -project and qmake Prog.pro.

When I run the Makefile I get this error:

mainwindow.h:11:21: fatal error: QtWidgets: No such file or directory
 #include <QtWidgets>

I have to add the line

QT += widgets

To the .pro file to compile correctly. Is there a way to do this automatically?

like image 236
Quaxton Hale Avatar asked Dec 17 '25 15:12

Quaxton Hale


1 Answers

Is there a way to do this automatically?

Yes and no.

You could run qmake like this:

qmake -project "QT+=widgets"

and then it is generated properly, but other than that from the command line, no. Also, note that you would like to use a guard if you plan to support Qt 4, too:

greaterThan(QT_MAJOR_VERSION, 4):QT+=widgets

If you happen to use QtCreator, you will be able to avoid all this as the IDE will generate this all for you automatically.

Also, you should be able to avoid including the whole module with all the classes even though you do not use them all. So, instead of writing this:

#include <QtWidgets>

You could write:

#include <Foo>
#include <Bar>
...
like image 122
lpapp Avatar answered Dec 19 '25 05:12

lpapp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!