• 9150阅读
  • 3回复

window+vc.net环境下QT4的安装--中文 [复制链接]

上一主题 下一主题
离线seraphliu
 

只看楼主 倒序阅读 楼主  发表于: 2006-04-25
这几天使用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来更新。
 
  十二、略
    。。。。。。。。。。。
  十三、略
    。。。。。。。。。。
离线javaguru
只看该作者 1楼 发表于: 2007-03-18
早知道你这有翻译的,我就不看英文版的啦
离线smartdj

只看该作者 2楼 发表于: 2008-06-27
这东西应该置顶.
命令提示符只是在运行的时候读取环境配置,如果使用qmake的时候出现如下提示

'qmake' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

重新启动命令提示符就可以了
离线heber386
只看该作者 3楼 发表于: 2008-08-14
我执行到第四步,直接运行installpatch411.bat
出现下述内容:请教大家,有没有谁知道是什么原因,该怎么改正?谢谢!
patching file qconfigure.bat
can't find file to patch at input line 111
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|Index: examples/threads/waitconditions/waitconditions.pro
|===================================================================
|RCS file: /cvsroot/qtwin/qt-4/examples/threads/waitconditions/waitconditions.pr
o,v
|retrieving revision 1.1.1.4
|retrieving revision 1.4
|diff -u -r1.1.1.4 -r1.4
|--- examples/threads/waitconditions/waitconditions.pro 20 Dec 2005 19:47:47 -00
00      1.1.1.4
|+++ examples/threads/waitconditions/waitconditions.pro 21 Dec 2005 19:53:50 -00
00      1.4
--------------------------
File to patch:
快速回复
限100 字节
 
上一个 下一个