我对 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