Qt/Qt Creator - The program has unexpectedly finis

2019-06-25 23:54发布

I'm somewhat new to C++ and to Qt 5.2.1. I'm actually learning how to use Qt. To do it as easy as possible, I'm using Qt Creator 3.0.1.

I've written this little piece of code in the main.cpp file of my project :

#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QPushButton bouton("Hello !");
    bouton.show();

    return app.exec();

}

And the .pro file (by default) :

SOURCES += \
    main.cpp

I tried to make it run, then I got the issue "QApplication : no such file or directory".

Then, I added "QT += widgets" to the .pro file (full file) :

SOURCES += \
    main.cpp
QT += widgets

And now I get :

Starting <path to .exe>... 
The program has unexpectedly finished.
<path to .exe> crashed

Please, tell me how to make it work. Thanks for reading and for your help.

(OS : Windows 7, Debug : Desktop Qt 5.2.1 MinGW 32bit)

Compile Output :

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.

Application Output :

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

2条回答
看我几分像从前
2楼-- · 2019-06-26 00:22

I've look all over the web, seeking how to install Qt5. There's not enough tutorials on it and it's very puzzling to make it work properly on Windows.

I have finally installed Qt4, which is more stable and easier to make it work.

查看更多
混吃等死
3楼-- · 2019-06-26 00:24

The code looks good. One explanation for what you get would be incompatible DLLs (e.g. Debug vs Release builds, or MSVC vs MinGW). You could start depends.exe with your .exe and check whether it picks up libraries from unexpected locations.

查看更多
登录 后发表回答