QDialog 没有这个文件或目录 - Qt Windows

12

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

我试图打开一个在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

还有许多其他的。

我将qmake.exe路径添加到了PATH中...我需要做些什么吗?

2个回答

20

阅读 Qt4Qt5 的过渡指南。链接1 链接2 链接3

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

8

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

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

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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接