【发布时间】:2014-02-08 14:18:39
【问题描述】:
我对 C++ 和 Qt 5.2.1 有点陌生。我实际上正在学习如何使用 Qt。为了尽可能简单,我使用的是 Qt Creator 3.0.1。
我在我的项目的 main.cpp 文件中编写了这段小代码:
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton bouton("Hello !");
bouton.show();
return app.exec();
}
还有 .pro 文件(默认):
SOURCES += \
main.cpp
我试图让它运行,然后我得到了问题“QApplication:没有这样的文件或目录”。
然后,我在 .pro 文件(完整文件)中添加了“QT += widgets”:
SOURCES += \
main.cpp
QT += widgets
现在我明白了:
Starting <path to .exe>...
The program has unexpectedly finished.
<path to .exe> crashed
请告诉我如何使它工作。 感谢您的阅读和帮助。
(操作系统:Windows 7,调试:桌面 Qt 5.2.1 MinGW 32 位)
编译输出:
16:06:54: Running steps for project test...
16:06:54: Configuration unchanged, skipping qmake step.
16:06:54: Starting: "C:\Qt\Tools\mingw48_32\bin\mingw32-make.exe"
C:/Qt/Tools/mingw48_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/PLD/Documents/PLD/Projets Codages/Qt/Qt/build-test-Desktop_Qt_5_2_1_MinGW_32bit-Debug'
mingw32-make[1]: Nothing to be done for 'first'.
mingw32-make[1]: Leaving directory 'C:/Users/PLD/Documents/PLD/Projets Codages/Qt/Qt/build-test-Desktop_Qt_5_2_1_MinGW_32bit-Debug'
16:06:55: The process "C:\Qt\Tools\mingw48_32\bin\mingw32-make.exe" exited normally.
16:06:55: Elapsed time: 00:01.
应用程序输出:
Starting C:\Users\PLD\Documents\PLD\Projets Codages\Qt\Qt\build-test-Desktop_Qt_5_2_1_MinGW_32bit-Debug\debug\test.exe...
The program has unexpectedly finished.
C:\Users\PLD\Documents\PLD\Projets Codages\Qt\Qt\build-test-Desktop_Qt_5_2_1_MinGW_32bit-Debug\debug\test.exe crashed
【问题讨论】:
-
是的,程序在工作配置上运行良好,Qt 示例对你有用吗?也许您也可以运行调试并查看崩溃时显示的调用堆栈。
-
@Predelnik 示例的相同问题:“程序意外完成”。
-
好吧,我可以建议尝试在调试中编译你的程序,看看它到底在哪里崩溃,它至少可以给出一些提示。
-
哇,你最好不要像这样在 cmets 中发布它,而是使用
pastebin.com或类似的东西。实际上你的编译和应用程序日志不是很有趣,我的意思是使用某种 IDE 或 gdb 来查看你的程序崩溃的地方的调用堆栈。 -
我想说从头开始执行以下操作 - 新文件或项目 - 选择 - QT Widget Application - 在 Applications 下。给个名字。下一步,最后代码就准备好了。现在,在 main.cpp 中用你的东西覆盖。如果没有环境问题,它应该可以工作。
标签: c++ qt qt-creator