Qt使用笔记(2)--Qmake的使用

阅读书:C++ GUI Programming with Qt 4, Second Edition,按照其指示,做了第一个例子,并按其说明使用如下批处理,进行了编译:

rem 设置vs的环境变量
set oldpath=%path%
set path="C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools";"D:\Qt\lib4.4.3\bin";%path%
call vsvars32.bat
qmake -project
qmake  hello.pro
nmake
set path=%oldpath% 

过程成功。窃喜了一下,但随之问题来啦。这个批处理不具有一般性,对于不同的例子都得修改相应的工程名字(这里是hello.pro).

 

带着这个问题对qmake一阵狂搜,得出了一个有启发的方案,将批处理修改如下:

rem 设置vs的环境变量
set oldpath=%path%
set path="C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools";"D:\Qt\lib4.4.3\bin";%path%
call vsvars32.bat
qmake -project
qmake 
nmake
set path=%oldpath% 

效果还不错,可以在不同的例子中使用,不须要修改啦。但还是有点不足,须要对一个工程进行调试怎么办?研究qmake manual 半天找出了如下方案,再次修改批处理如下:

rem 设置vs的环境变量
set oldpath=%path%
set path="C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools";"D:\Qt\lib4.4.3\bin";%path%
call vsvars32.bat
qmake -project
qmake 
qmake -tp vc 
nmake
set path=%oldpath% 

 

使用以上批处理,除了可对工程进行相应的编译生成以外,还可以生成一个。vcproj 文件,可以使用你的VS打开,可以进行相应的编译调试工作啦。

但上面的命令只是知其然而不知其所以然,将qmake -h运行一下,终天有点明白啦。

Usage: qmake [mode] [options] [files]

QMake has two modes, one mode for generating project files based on
some heuristics, and the other for generating makefiles. Normally you
shouldn't need to specify a mode, as makefile generation is the default
mode for qmake, but you may use this to test qmake on an existing project

Mode:
  -project Put qmake into project file generation mode
  In this mode qmake interprets files as files to
  be built,
  defaults to *.c; *.ui; *.y; *.l; *.ts; *.xlf; *.qrc; *.h; *.hpp; *.hh; *.hxx; *.cpp; *.cc; *.cxx
  -makefile Put qmake into makefile generation mode (default)
  In this mode qmake interprets files as project files to
  be processed, if skipped qmake will try to find a project
  file in your current working directory

Warnings Options:
  -Wnone Turn off all warnings
  -Wall Turn on all warnings
  -Wparser Turn on parser warnings
  -Wlogic Turn on logic warnings

Options:
  * You can place any variable assignment in options and it will be *
  * processed as if it was in [files]. These assignments will be parsed *
  * before [files]. *
  -o file Write output to file
  -unix Run in unix mode
  -win32 Run in win32 mode
  -macx Run in Mac OS X mode
  -d Increase debug level
  -t templ Overrides TEMPLATE as templ
  -tp prefix Overrides TEMPLATE so that prefix is prefixed into the value
  -help This help
  -v Version information
  -after All variable assignments after this will be
  parsed after [files]
  -norecursive Don't do a recursive search
  -recursive Do a recursive search
  -cache file Use file as cache [makefile mode only]
  -spec spec Use spec as QMAKESPEC [makefile mode only]
  -nocache Don't use a cache file [makefile mode only]
  -nodepend Don't generate dependencies [makefile mode only]
  -nomoc Don't generate moc targets [makefile mode only]
  -nopwd Don't look for files in pwd [project mode only]

1.qmake -project 

此命令使用 -project 模式,当不输入文件时,其以如下文件为输入。:defaults to *.c; *.ui; *.y; *.l; *.ts; *.xlf; *.qrc; *.h; *.hpp; *.hh; *.hxx; *.cpp; *.cc; *.cxx,并生成相应的pro文件。我这里是test001.pro。

2.qmake

此命令使用默认模式 -makefile,当不输入文件时,以当前目录下的工程文件作为输入(qmake will try to find a project
  file in your current working directory),我这里是test001.pro。

3.qmake -tp vc

这个用来生成文件:test001.vcproj

4.nmake

以当前的makefile作为输入。对于这个makefile的内容,我暂时还没有读懂,明白了再与各位分亨。

初试qmake感到还是很强大,但也很易用的,比bakefile要易入门些。

2009.08.06
最近使用qmake 又有了一些认识.以上是用在生成一个GUI的程序,若是要生成一个CONSOLE程序,则应该使用如下批处理.
   

rem 设置vs的环境变量
set oldpath=%path%
set path="C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools";"D:\Qt\4.5.2\bin";%path%
call vsvars32.bat

nmake distclean
REM ~ qmake -help
qmake -project CONFIG+=console
qmake
qmake -tp vc
nmake
set path=%oldpath%
pause


总结:
        对于QMAKE我们可以使用一个赋值对作参考.(You may also pass assignments on the command line in this mode.)




 

posted @ 2009-02-13 15:43  黄彬子  阅读(5772)  评论(0编辑  收藏  举报