windows 错误:'QtGui/QMainWindow':没有那个文件或目录:Qt 5.1.1

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20314090/
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 11:08:17  来源:igfitidea点击:

Error : 'QtGui/QMainWindow': No such file or directory : Qt 5.1.1

windowsqt5.1

提问by kalryoma

I have installed the Qt5.1.1and create a new Gui Application. The code in mainwindow.h shows:

我已经安装Qt5.1.1并创建了一个新的 Gui 应用程序。mainwindow.h 中的代码显示:

#if QT_VERSION >= 0x050000
#include <QtWidgets/QMainWindow>
#else
#include <QtGui/QMainWindow>
#endif

I think it is fine. But when I run it, I have this:

我觉得还好。但是当我运行它时,我有这个:

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

I know when I replace

我知道什么时候更换

#if QT_VERSION >= 0x050000
#include <QtWidgets/QMainWindow>
#else
#include <QtGui/QMainWindow>
#endif

to

#include <QtWidgets/QMainWindow>

it works.

有用。

I just wonder why the default code is wrong and how to make the defauly code right.

我只是想知道为什么默认代码是错误的以及如何使默认代码正确。

回答by AB Bolim

You may have another option.

您可能还有其他选择。

You can also add widgetsin your .profile like

你也可以widgets在你的.pro文件中添加

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

By adding this line in .profile, Now you just no need to worry about Qt version and include file like <QtGui/QMainWindow>or <QtWidgets/QMainWindow>

通过在.pro文件中添加这一行,现在您无需担心 Qt 版本和包含文件,例如<QtGui/QMainWindow><QtWidgets/QMainWindow>

Hope it will useful to you.

希望对你有用。

回答by lebendig

I had the same problem, but it is with nuances. If that code is in the .hfile:

我有同样的问题,但有细微差别。如果该代码在.h文件中:

    #if QT_VERSION >= 0x050000
    #include <QtWidgets/QMainWindow>
    #else
    #include <QtGui/QMainWindow>
    #endif

the error appears. It seems like QT_VERSION does not defined correctly. But if I move this code to the .cppfile, it is all right. The problem was solved as follows:
1. Add to the .profile this:

出现错误。似乎 QT_VERSION 没有正确定义。但是如果我把这段代码移到.cpp文件中,那就没问题了。问题解决如下:
1. 在.pro文件中添加:

    greaterThan(QT_MAJOR_VERSION, 4) {
        QT += widgets
        DEFINES += HAVE_QT5
    }

2. Add to the .hfile this:

2. 将以下内容添加到.h文件中:

    #ifdef HAVE_QT5
    #include <QtWidgets/QMainWindow>
    #else
    #include <QtGui/QMainWindow>
    #endif