C++ 编译时报错:'QtGui/QAction' file not found #include <QtGui/QAction>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21551557/
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
When compiling get error: 'QtGui/QAction' file not found #include <QtGui/QAction>
提问by Celeritas
I just installed Mac OS X 10.8.3 and Qt Creator 3, XCode, and XCode command line tools. I'm trying to compile a project that works on another computer but each time I go to "build all" I get error: 'QtGui/QAction' file not found
in #include <QtGui/QAction>
我刚刚安装了 Mac OS X 10.8.3 和 Qt Creator 3、XCode 和 XCode 命令行工具。我正在尝试编译一个可以在另一台计算机上运行的项目,但每次我去“全部构建”时,我都会error: 'QtGui/QAction' file not found
进入#include <QtGui/QAction>
I tried adding the second and third line in the .pro file but it didn't help
我尝试在 .pro 文件中添加第二行和第三行,但没有帮助
QT += core gui opengl
CONFIG += qt
QT += gui
TARGET = BasicOpenGL
TEMPLATE = app
UPDATE: I also tried this .pro file and it didn't work
更新:我也试过这个 .pro 文件,但没有用
QT += core gui opengl
QT += widgets
TARGET = BasicOpenGL
TEMPLATE = app
I should say this is my first time attempting development on mac.
我应该说这是我第一次尝试在 mac 上开发。
Compile Output from Qt
从 Qt 编译输出
Versions/A/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I. -F/Users/john/Qt/5.2.0/clang_64/lib -o mainwindow.o ../Framework/mainwindow.cpp
In file included from ../Framework/mainwindow.cpp:2:
../Framework/ui_mainwindow.h:14:10: fatal error: 'QtGui/QAction' file not found
#include <QtGui/QAction>
^
1 error generated.
make: *** [mainwindow.o] Error 1
15:51:32: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project BasicOpenGL (kit: Desktop Qt 5.2.0 clang 64bit)
When executing step 'Make'
UPDATE: I got it to work but with all the screwing around I'm not exactly sure what did it. I started with a fresh mac image, installed system updates, installed xcode, installed xcode command line tools, installed QT Creator 3.0, installed QT libraries 4.8.1, setup the compilers in QT Creator.
更新:我让它工作了,但由于所有的问题,我不确定它做了什么。我从一个新的 mac 镜像开始,安装系统更新,安装 xcode,安装 xcode 命令行工具,安装 QT Creator 3.0,安装 QT 库 4.8.1,在 QT Creator 中设置编译器。
回答by JPaget
Try doing a make clean
followed by a make
. I had this exact problem on a Windows 7 system, and this is what worked for me.
尝试执行 amake clean
后跟 a make
。我在 Windows 7 系统上遇到了这个确切的问题,这对我有用。
回答by hluk
In Qt5, QAction
header is in QtWidgets
include sub-directory, not in QtGui
(that's true for Qt4). Though you don't actually need to specify include sub-directories since qmake
will handle that for you. You just need to add QT += widgets
to your .pro
file.
在 Qt5 中,QAction
头文件在QtWidgets
include 子目录中,而不是在QtGui
(对于 Qt4 来说是这样)。尽管您实际上并不需要指定包含子目录,因为它qmake
会为您处理。您只需要添加QT += widgets
到您的.pro
文件中。
回答by Yini Guo
Set the version to Qt5, change all #include<QtQui/*>
s into #include<QtWidgets/*>
.
And add QT += widgets
in your .pro file.
Rebuild the project, when you get the error again, tap into the error message, and change the #include<QtQui/*>
s into #include<QtWidgets/*>
too.
设置版本为Qt5,将#include<QtQui/*>
s全部改成#include<QtWidgets/*>
. 并添加QT += widgets
您的 .pro 文件。重建项目,当你再次出现错误时,点击错误信息,将#include<QtQui/*>
s也改成#include<QtWidgets/*>
。