Qt/Qt Creator - 程序意外完成。 <程序路径>崩溃了

2024-01-07

我对 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:没有这样的文件或目录”。

然后,我将“QT += widgets”添加到 .pro 文件(完整文件)中:

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

代码看起来不错。对您所得到的结果的一种解释是 DLL 不兼容(例如,调试版本与发布版本,或者 MSVC 与 MinGW)。您可以使用 .exe 启动 dependent.exe 并检查它是否从意外位置获取库。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Qt/Qt Creator - 程序意外完成。 <程序路径>崩溃了 的相关文章

随机推荐