//**************windows xp平台******************
根据C++ GUI Qt4书本步骤,安装qt-sdk-win-opensource-2010.04.exe
运行Qt Creator
打开hello.pro工程
直接运行:run可以得到hello qt!程序,如下图
方式二:
通过Qt Command Prompt进入command窗口
打开这个窗口会自动设置使用MinGW编译器编译qt程序时所需的环境变量!
>cd E:\Downloads\qtopia\qt-book\chap01\hello
>qmake –project
>qmake hello.pro
>make
书籍上介绍使用的是make命令,提示“make不是内部或外部命令”
从论坛上得知,使用的是mingw32-make
> mingw32-make
>cd debug
>hello
同样得到以上效果!
//**************Fedora9平台******************
cd /tmp
下载直接运行qt-sdk-linux-x86-opensource-2010.04.bin
tar zxvf qt-everywhere-opensource-src-4.6.3.tar.gz
因为Fedora9预装了qt3 designer 和qt4 designer!
同样进行make之后,发现出现以下问题:
[root@localhost hello-qt]# qmake -project
[root@localhost hello-qt]# qmake hello-qt.pro
[root@localhost hello-qt]# make
g++ -c -pipe -Wall -W -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -DQT_THREAD_SUPPORT -I/usr/lib/qt-3.3/mkspecs/default -I. -I. -I/usr/lib/qt-3.3/include -o hello.o hello.cpp
hello.cpp:1:24: 错误:QApplication:没有那个文件或目录
hello.cpp:2:18: 错误:QLabel:没有那个文件或目录
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:6: 错误:‘QApplication’在此作用域中尚未声明
hello.cpp:6: 错误:expected `;' before ‘app’
hello.cpp:7: 错误:‘QLabel’在此作用域中尚未声明
hello.cpp:7: 错误:‘label’在此作用域中尚未声明
hello.cpp:7: 错误:expected type-specifier before ‘QLabel’
hello.cpp:7: 错误:expected `;' before ‘QLabel’
hello.cpp:9: 错误:‘app’在此作用域中尚未声明
hello.cpp: At global scope:
hello.cpp:4: 警告:未使用的参数‘argc’
hello.cpp:4: 警告:未使用的参数‘argv’
make: *** [hello.o] 错误 1
[root@localhost hello-qt]# gedit Makefile
发现INCPATH的路径不对,没有QT4的路径
[root@localhost hello-qt]# $PATH
返回来查看PATH的路劲为
bash: /usr/local/arm/4.3.2/bin:/usr/local/arm/4.3.2/bin:/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin: 没有那个文件或目录
没有QT4/bin的路径,即使用的qmake非QT4 Creator的
[root@localhost hello-qt]# export PATH=/usr/local/arm/4.3.2/bin:/usr/local/arm/4.3.2/bin:/usr/lib/qt4/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
更改后为以上状态;
[root@localhost hello-qt]# $PATH
bash: /usr/local/arm/4.3.2/bin:/usr/local/arm/4.3.2/bin:/usr/lib/qt4/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin: 没有那个文件或目录
重新编译
[root@localhost hello-qt]# qmake -project
[root@localhost hello-qt]# qmake hello-qt.pro
[root@localhost hello-qt]# make
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -I. -I. -I. -o hello.o hello.cpp
g++ -o hello-qt hello.o -lQtGui -lQtCore -lpthread
[root@localhost hello-qt]# ./hello-qt
可以发现windows与linux平台的窗口界面不同!