【发布时间】:2016-07-24 07:33:04
【问题描述】:
我知道网上有几个关于类似问题的问题,但不幸的是,它们都没有帮助我解决这个看起来相对简单的问题,正如标题所示。
我设置了一个出现问题的最小 Qt 项目:
├── main.cpp
├── mainwindow.ui
└── qt.pro
main.cpp:
#include <QtWidgets/QtWidgets>
#include "ui_mainwindow.h"
int main () {
return 0;
}
qt.pro:
TEMPLATE = app
TARGET = qt-qmake-uic-problem
INCLUDEPATH += .
# Input
FORMS += mainwindow.ui
SOURCES += main.cpp
文件mainwindow.ui是Qt Creator提供的默认MainWindow Form。
现在如果我跑
qmake qt.pro
然后在执行 make 时会创建一个 Makefile 导致此错误:
[developer@kdb qt-qmake-uic-problem]$ make
g++ -c -pipe -O2 -march=i686 -mtune=generic -O2 -pipe -fstack-protector-strong -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/qt -isystem /usr/include/qt/QtGui -isystem /usr/include/qt/QtCore -I. -I/usr/lib/qt/mkspecs/linux-g++ -o main.o main.cpp
main.cpp:2:28: fatal error: ui_mainwindow.ui: No such file or directory
#include "ui_mainwindow.h"
^
compilation terminated.
make: *** [Makefile:298: main.o] Error 1
据我所知,ui_mainwindow.h 必须由 qmake 或 Makefile 生成 - 而不是我自己手动调用 uic。我必须注意,moc 也会发生类似的事情,并且在进行研究时,我在文档和类似问题中都没有找到解释,尽管如果这个 qmake 安装被破坏会很奇怪——我正在运行 Arch Linux并从默认存储库中获取 Qt SDK。
非常感谢您的建议!
【问题讨论】:
-
尝试包含
mainwindow.ui而不是ui_mainwindow.ui -
感谢您的快速回复!不幸的是,它没有用,结果是一样的。没有生成文件,g++ 抛出“没有这样的文件或目录”错误。
-
@wasthishelpful ,它是
ui_mainwindow.h。在cpp文件main.cpp中包含mainwindow.uixml文件是不合逻辑的 -
当然我尝试了使用以 .h 结尾的文件的解决方案,假设 .ui 是一个错字。