大家好。我最近要学习qt编程,可是目前一点qt的基础也没有,昨天下载了Qt软件按遇到了问题,希望大家能给点帮助。
学习qt的官方书籍是C++ GUI Qt4,目前我看的是第二版,书中用的是Qt4.3.2,相信有人也看过本书了。但是在我编写第一个例子hello qt时便遇到了困难,真是出师未捷身先死啊。
我安装的是最新版本的Qt4.7的sdk,基于windows平台的。安装过程很傻瓜,所有组件都是按默认安装的。
安装完后,我试着用nokia的工具Qt Creator创建了一个Qt GUI工程,没问题,运行正常。但是下面又编写了一个基于控制台的hello qt,编译时却报错。我想问问,是不是需要配置什么环境之类的。我的第一个hello qt竟然让我如此纠结,还请不吝赐教。附源码和编译信息。
#include <QtCore/QCoreApplication> //此处和原书的4.3版中的 头文件路径有所差异
#include <Qt/qlabel.h> //同上
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return a.exec();
}
以下是编译输出:
Running build steps for project hello...
Configuration unchanged, skipping qmake step.
Starting: "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `C:/Qt/2010.05/hello'
C:/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Qt/2010.05/hello'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug\hello.exe debug/main.o -L"c:\Qt\2010.05\qt\lib" -lQtCored4
mingw32-make[1]: Leaving directory `C:/Qt/2010.05/hello'
mingw32-make: Leaving directory `C:/Qt/2010.05/hello'
debug/main.o: In function `main':
C:\Qt\2010.05\hello/main.cpp:7: undefined reference to `_imp___ZN6QLabelC1ERK7QStringP7QWidget6QFlagsIN2Qt10WindowTypeEE'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\hello.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project hello (target: Desktop)
When executing build step 'Make'
注:我的qt安装路径在C:\Qt\2010.05,安装组件包含mingw。有人说去掉Shadow Build的对勾即可,我试了下没有成功。