【问题标题】:Qt/Qt Creator - The program has unexpectedly finished. <program's path> crashedQt/Qt Creator - 程序意外完成。 <程序路径> 崩溃
【发布时间】: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


【解决方案1】:

代码看起来不错。对您得到的结果的一种解释是不兼容的 DLL(例如 Debug 与 Release 构建,或 MSVC 与 MinGW)。您可以使用您的 .exe 启动depends.exe,并检查它是否从意外位置获取库。

【讨论】:

  • 我有一个案例,我在“发布”目录中有一些 .Qt 运行时 dll。删除它们从 QtCreator 中解决了我的问题。从 Windows 资源管理器运行程序会产生运行时错误,说明 .dll 中缺少入口点。
【解决方案2】:

我浏览了整个网络,寻找如何安装 Qt5。没有足够的教程,让它在Windows上正常工作非常令人费解。

我终于安装了Qt4,它更稳定,更容易让它工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 2021-06-14
    • 1970-01-01
    相关资源
    最近更新 更多