简体   繁体   English

在Qmake中使用Qtwidgets

[英]Using Qtwidgets with Qmake

I am building my Qt Application with qmake -project and qmake Prog.pro . 我建立我的Qt应用程序中qmake -projectqmake Prog.pro

When I run the Makefile I get this error: 当我运行Makefile时,出现以下错误:

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. 到.pro文件以正确编译。 Is there a way to do this automatically? 有没有一种方法可以自动执行此操作?

Is there a way to do this automatically? 有没有一种方法可以自动执行此操作?

Yes and no. 是的,没有。

You could run qmake like this: 您可以这样运行qmake:

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: 另外,请注意,如果您计划也支持Qt 4,则也希望使用防护罩:

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. 如果您碰巧使用QtCreator ,那么您将能够避免所有这些,因为IDE会自动为您生成所有这些。

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>
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM