window+vc.net环境下QT4的安装--中文
这几天使用QT,看到这片http://www.qtcn.org/bbs/read.php?tid=3449关于安装的文章不错,就以自己的这点e文水平翻译了一下,供大家学习参考,如果哪里有上面不妥的,请提意见。谢谢!源文地址:http://qtnode.net/wiki/Qt4_with_Visual_Studio编译QT4.1.1-、获取和安装QT 4.1.1 1.获得Qt源码压缩包qt-win-opensource-src-4.1.1.zip(http://www.qtcn.org/download/qt-win-opensource-src-4.1.1.zip) 2.解压源码包,建议路径: C:\Qt\4.1.1\ (如果使用VC6.0) C:\Qt\4.1.1-msvc\ (如果使用VC.net 20003) C:\Qt\4.1.1-msvc2005\ (如果使用vc2005)二、获取QT 4.1.1补丁Qtnode-acs-qt4.1.1.zip,用于windows下安装QT 4.1.1(http://www.qtcn.org/download/qt-win-opensource-src-4.1.1.zip),解压补丁包到上面的对应的目录。三、准备开始编译QT 4.1.1 打开一个命令行定位QT源码目录(根据上面的目录),必须确保设置好你的编译器路径(主要是环境变量path,include及lib里必须包含vc的相关路径) 建议:如果使用vc6.0,在命令行运行vcvars32.bat; 如果使用vc.net 2003或者2005,直接从VC的工具里运行命令行(开始->程序->VC.net->vc.net tools->vc .net command prompt) 测试你是否正确的设置好环境的方法是在当前命令行下运行nmake /? 例如:C:\Qt\4.1.1> nmake /? Microsoft (R) Program Maintenance Utility Version 8.00.50727.42 Copyright (C) Microsoft Corporation. All rights reserved. Usage: NMAKE @commandfile NMAKE [options] [/f makefile] [/x stderrfile] [macrodefs] [targets] Options: .... 出现上面的提示,说明的你的环境已经OK了 四、打补丁;如果QT源码目录下已经有补丁文件的话,直接运行installpatch411.bat C:\Qt\4.1.1> installpatch411.bat 你将看到: C:\Qt\4.1.1> installpatch411.bat patching file qconfigure.bat patching file examples/threads/waitconditions/waitconditions.pro patching file misc/bcc32pch/Makefile.win32-borland patching file misc/bcc32pch/bcc32pch.cpp patching file misc/bcc32pch/bcc32pch.pri patching file misc/bcc32pch/bcc32pch.pro patching file mkspecs/win32-bccx/qmake.conf ...... ...... ...... patching file tools/porting/src/rpptreeevaluator.cpp patching file tools/porting/src/rpptreewalker.cpp patching file tools/porting/src/src.pro Press any key to continue . . . Now run qconfigure.bat 五、配置Qt和编译qmake 在这里我们不是QT自带的标准的configure.exe,而使用补丁中qconfigure.bat;如果你想改变编译选项的话,可以运行configure.exe --help查看相关的选项。 运行configure.exe --help 将会列出所有的选项,你可以通过打星号选择自己感兴趣的。已经打星号的是默认选项。 在这里我们使用补丁中qconfigure.bat,qconfigure.ba需要编译器作为参数 * msvc <- if you are using Visual Studio 6.0 * msvc.net <- if you are using Visual Studio .NET (2003) * msvc2005 <- if you are using Visual Studio 2005 运行了qconfigure.bat后,会有三次提示: a. 接受GPL license,敲'y'; b.开始编译qmake,敲'y'; c.建立makefile,敲'y'. 接着你会看到提示信息: ==================================================== You are now ready to build Qt (msvc2005) If you specified -static, type 'nmake sub-src' otherwise, type 'nmake' To start over, type 'nmake distclean' and then re-run qconfigure.bat ==================================================== 大概是说:要编译静态库使用'namke sub-src',否则使用'nmake' 结束后 敲入'nmake distclean'并且重新运行'qconfigure.bat'六、编译QT库: C:\Qt\4.1.1> nmake (编译非静态库, 通常情况) C:\Qt\4.1.1> nmake sub-src (编译静态库) waiting............ 七、建立环境: 有很多建立环境的方法,这里使用最简单的一种 设置QT 库的路径,根据你的源码的存放目录,在环境变量path增加C:\Qt\4.1.2\bin,lib中增加C:\Qt\4.1.2\lib,include中增加C:\Qt\4.1.2\include 设置windows环境变量,详细参考 http://www.cs.usask.ca/grads/wew036/latex/env.html 当环境变量改变后,必须重新打开命令行!八、检查环境便量path: C:\> qmake -v QMake version: 2.00a Using Qt version 4.1.2 in C:\Qt\4.1.2\lib九、检查QMAKESPEC C:\> echo %QMAKESPEC% win32-msvc.net 十、测试你的安装 1.首先测试命令行(例子:hello) a.建立一个hello.cpp,内容如下: #include <QApplication> #include <QLabel> int main(int argc, char **argv) { QApplication app(argc, argv); QLabel *label = new QLabel("Hello World!"); label->show(); return app.exec(); } b.用qmake创建一个工程文件 prompt> qmake -project -o hello.pro 在你的工程目录下出现了一个hello.pro,用来生成makefile c.用qmake创建Makefile,在命令行直接运行qmake prompt> qmake d.编辑你的程序 prompt> nmake e.运行你的程序 prompt> debug\hello 2.创建visual studio工程 a.根据上面的方法创建一个工程hello.pro b.创建适用于vc.net的hello.vcproj prompt> qmake -project -t vcapp -o hello.pro prompt> qmake 这样你的工程目录下就有了hello.vcproj工程文件,你就可以在vc.net中打开它了 十一、维护visual studio工程 给工程中增加文件时,可以通过编辑.pro文件并且重新运行qmake,唯一的问题就是.sln的内容不能再用,必须通过重新打开.vcproj来更新。 十二、略 。。。。。。。。。。。 十三、略 。。。。。。。。。。