You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Qt Creator编译C++软件时无法找到QtGui头文件求助

Fixing "QtGui/QMainWindow: No such file or directory" Error in Qt Creator

Hey there! I’ve run into similar head-scratching issues when working with Qt4 projects in Qt Creator, so let’s walk through the most likely fixes for your problem:

1. Make sure you’re using a Qt4 kit in Qt Creator

Qt5 and later split GUI components into separate modules—QMainWindow moved to QtWidgets instead of staying in QtGui. Since your headers live in /usr/include/qt4/QtGui, you need to confirm your project is tied to a Qt4 kit:

  • Open your project in Qt Creator, switch to the Projects tab (left sidebar).
  • Under Build & Run, check the active kit. It should list a Qt4 version (like Qt 4.8.7) instead of Qt5/Qt6.
  • If no Qt4 kit exists, add one via Tools -> Options -> Kits -> Add, pointing to your Qt4 installation (look for the qmake binary in your Qt4 bin directory, usually something like /usr/bin/qmake-qt4).

2. Double-check your project’s .pro file

Your .pro file needs to explicitly include the gui module for Qt4. Open the file and confirm this line is present:

QT += gui

If you accidentally added QT += widgets (which is for Qt5+), that’ll throw things off—stick with gui for Qt4 projects.

3. Manually add the Qt4 include path to build settings

Sometimes Qt Creator doesn’t auto-detect the Qt4 include directory correctly. Let’s add it manually:

  • Go to Projects -> Build Settings -> [Your Active Compiler] -> Include paths.
  • Click Add and enter /usr/include/qt4. This tells the compiler to look for subdirectories like QtGui within this path, which matches your #include <QtGui/QMainWindow> syntax perfectly.

4. Clean and rebuild your project

Old build artifacts or cached config can sometimes cause false "file not found" errors. Do a full reset:

  • Click Build -> Clean All to wipe existing build files.
  • Then click Build -> Rebuild All to compile everything from scratch.

If none of these work, quickly verify the file actually exists by running ls /usr/include/qt4/QtGui/QMainWindow in the terminal. You might also check file permissions—ensure your user has read access to that directory and its files.


内容的提问来源于stack exchange,提问作者S.EB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:13:18