编译时获取错误:找不到'QtGui/QAction'文件#include <QtGui/QAction>

Cel*_*tas 8 c++ macos qt

我刚刚安装了Mac OS X 10.8.3和Qt Creator 3,XCode和XCode命令行工具.我正在尝试编译一个可以在另一台计算机上运行的项目,但每次我去"构建所有"我都会error: 'QtGui/QAction' file not found 进入#include <QtGui/QAction>

我尝试在.pro文件中添加第二行和第三行,但它没有帮助

QT       += core gui opengl
CONFIG += qt
QT += gui
TARGET = BasicOpenGL
TEMPLATE = app
Run Code Online (Sandbox Code Playgroud)

更新:我也试过这个.pro文件但它没有用

QT       += core gui opengl
QT += widgets
TARGET = BasicOpenGL
TEMPLATE = app
Run Code Online (Sandbox Code Playgroud)

我应该说这是我第一次尝试在mac上进行开发.

从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'
Run Code Online (Sandbox Code Playgroud)

更新:我得到了它的工作,但所有的拧紧我不确定是什么做的.我开始使用全新的mac映像,安装了系统更新,安装了xcode,安装了xcode命令行工具,安装了QT Creator 3.0,安装了QT库4.8.1,在QT Creator中设置了编译器.

JPa*_*get 18

尝试做一个make clean后跟一个make.我在Windows 7系统上遇到了这个问题,这对我有用.


hlu*_*luk 14

在Qt5中,QAction标题位于QtWidgetsinclude子目录中,而不是QtGui(在Qt4中为真).虽然您实际上不需要指定包含子目录,因为它qmake会为您处理.您只需要添加QT += widgets到您的.pro文件中.

  • 使用 QT Creator,将版本设置为 Qt5 并重建项目对我有用 (2认同)
  • 我在使用peercoin-qt 时遇到了这个问题。为了解决这个问题,我需要清理“build”目录并重新运行“qmake”,因为它似乎没有更新那些自动生成的头文件。 (2认同)