QDialog 不是这样的文件或目录 - Qt Windows

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14260475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:10:32  来源:igfitidea点击:

QDialog not such file or directory - Qt Windows

windowsqtqt-creator

提问by Nick L Scott

I just installed Qt Creator 2.6.1 based on Qt 5.0.

我刚刚安装了基于 Qt 5.0 的 Qt Creator 2.6.1。

I'm trying to open a project made on 4.8 but I can't compile it. It keeps showing me errors of "not such file or directory".

我正在尝试打开一个在 4.8 上制作的项目,但我无法编译它。它不断向我显示“不是这样的文件或目录”的错误。

error: C1083: Cannot open include file: 'QtGui/QApplication': No such file or directory 

error: C1083: Cannot open include file: 'QDialog': No such file or directory 

error: C1083: Cannot open include file: 'QMainWindow': No such file or directory 

error: C1083: Cannot open include file: 'QWidget': No such file or directory

And many more.

还有很多。

I added the qmake.exe path to PATH...do I need to do something else?

我将 qmake.exe 路径添加到 PATH...我需要做其他事情吗?

回答by pnezis

Read the transition guides from Qt4to Qt5. Link1Link2Link3

阅读从Qt4到的过渡指南Qt5链接1链路2链接3

One of the major internal infrastructural changes in Qt 5 compared to Qt 4 is the splitting of widgets from the QtGui module into a new QtWidgets module. This obviously will require buildsystem changes at least, but also causes the need for downstreams to add includes for headers which were not needed before, as those includes were removed from headers which now remain in the QtGui module.

Another includes-related issue in porting from Qt 4 to Qt 5 is dealing with includes for classes which have moved to the QtWidgets module. Whereas Qt 4 based code might use

与 Qt 4 相比,Qt 5 的主要内部基础结构变化之一是将小部件从 QtGui 模块拆分为新的 QtWidgets 模块。这显然至少需要更改构建系统,但也会导致下游需要为以前不需要的头文件添加包含,因为这些包含已从现在保留在 QtGui 模块中的头文件中删除。

从 Qt 4 移植到 Qt 5 的另一个与包含相关的问题是处理已移动到 QtWidgets 模块的类的包含。而基于 Qt 4 的代码可能会使用

#include <QtGui/QWidget>
This must be updated to either

#include <QtWidgets/QWidget>
Or more portably (Which works in Qt 4 and Qt 5):

#include <QWidget>

回答by rotovator

I had this problem, made two changes

我遇到了这个问题,做了两个更改

  1. echo "QT += widgets" >> /fileProject.pro

  2. add #include QDialog in the file containign QDialog declarations

  1. echo "QT += widgets" >> /fileProject.pro

  2. 在包含 QDialog 声明的文件中添加 #include QDialog

previously including QtGui was enough but QT5 splits widgets into more .h files, thus making necessary to include them. For example QtMenuBar was included in QtMenu.h but now it requires QtMenuBar.h to be #included

以前包含 QtGui 就足够了,但 QT5 将小部件拆分为更多 .h 文件,因此需要包含它们。例如 QtMenuBar 包含在 QtMenu.h 中,但现在它要求 QtMenuBar.h 被 #included