#include <QtCore/QCoreApplication>
#include <QtGui/QLabel>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QLabel label("Hello world");
label.show();
return a.exec();
}
我正在使用QTCreator,我在Windows上安装了QT 4.7。 现在我每次编译时都会收到此错误:
:: error: collect2: ld returned 1 exit status
With mingw32 giving me the following
tmp/obj/debug_shared/main.o: In function `main':
E:\Qt\2010.04\qt\QTHello-build-desktop/../QTHello/main.cpp:6: undefined reference to `_imp___ZN6QLabelC1ERK7QStringP7QWidget6QFlagsIN2Qt10WindowTypeEE'
E:\Qt\2010.04\qt\QTHello-build-desktop/../QTHello/main.cpp:8: undefined reference to `_imp___ZN6QLabelD1Ev'
E:\Qt\2010.04\qt\QTHello-build-desktop/../QTHello/main.cpp:8: undefined reference to `_imp___ZN6QLabelD1Ev'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\QTHello.exe] Error 1
mingw32-make: *** [debug-all] Error 2
The process "E:/Qt/2010.04/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project QTHello (target: Desktop)
When executing build step 'Make'
问题是什么?
答案 0 :(得分:5)
创建一个 Qt GUI项目,然后写下您所写的内容。
答案 1 :(得分:2)
您的项目文件可能不包含所需的内容。你有吗
TEMPLATE = app
或
QT += gui
你的.pro文件中的?
答案 2 :(得分:1)
你是否与QtGui联系?如果你不这样做,那就去做吧。
答案 3 :(得分:1)
此外,对于UI应用程序,您必须使用QApplication。 QCoreApplication仅适用于CLI工具。
答案 4 :(得分:0)
您想使用QT创建Hello World应用程序吗?真的很简单:
您已使用Qt
完成Hello World应用程序然后,如果您想知道如何编写QTGui应用程序,只需打开项目中的文件即可查看其中的内容。