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

Qt项目无法包含UI头文件问题求助(QtCreator4.5)

Fixing "no such file or directory" for Qt UI Header Files

Hey there, let's work through that UI header file error you're facing in your Qt project! I've run into this exact issue before, so here's what to check step by step:

1. Double-check your .pro file configuration

Qt uses the uic tool to generate ui_*.h header files from your .ui forms—but this only happens if you've added your .ui file to the FORMS variable in your .pro file. Make sure your .pro includes a line like:

FORMS += your_form_name.ui

Replace your_form_name.ui with the actual name of your UI file (e.g., gotocell.ui if you're following the gotocell1 example). Without this line, qmake won't tell uic to generate the header, so your compiler will never find it.

2. Verify your #include statement matches the generated header

The generated header file name follows the pattern ui_<your_form_name>.h. So if your UI file is gotocell.ui, the header will be ui_gotocell.h. Double-check that your main.cpp uses the correct name:

#include "ui_gotocell.h"

Note: If you're on a case-sensitive OS (like Linux), make sure the capitalization matches exactly—ui_GotoCell.h won't work if the generated file is ui_gotocell.h.

3. Re-run qmake and clean your build directory

Sometimes old build artifacts or an outdated Makefile can cause this issue. Here's how to refresh things in Qt Creator 4.5:

  • Go to the Build menu → select Run qmake (this ensures qmake updates the build rules to include your UI file).
  • Next, go to Build → Clean All to delete any old generated files.
  • Finally, rebuild your project with Build → Build All.

This forces Qt to regenerate the UI header file from scratch and ensures the compiler can find it in the build directory.

4. Check your build directory include path

Qt Creator usually automatically adds the build directory (where ui_*.h files are generated) to your compiler's include path. But if you've customized your project's build settings, you might need to double-check:

  • Open the Projects tab in Qt Creator.
  • Under Build & Run, look at your active build configuration's Build directory.
  • Ensure this directory is listed in your .pro file's INCLUDEPATH if you've manually set it:
    INCLUDEPATH += $$PWD/your_build_directory_path
    

(Replace your_build_directory_path with the actual path from your project settings.)

Quick comparison to the gotocell1 example

Take a look at the gotocell1 project's .pro file—you'll see it explicitly lists the UI file in FORMS, and the main source file includes the corresponding ui_*.h header. Matching that structure should resolve your issue.


内容的提问来源于stack exchange,提问作者jwm

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 07:49:05