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

摘要:
研究qmakemanual半天找出了如下方案,再次修改批处理如下:rem设置vs的环境变量setoldpath=%path%setpath="C:\ProgramFiles\MicrosoftVisualStudio9.0\Common7\Tools";"D:\Qt\lib4.4.3\bin";%path%callvsvars32.batqmake-projectqmakeqmake-tpvcnmakesetpath=%oldpath%使用以上批处理,除了可对工程进行相应的编译生成以外,还可以生成一个。对于这个makefile的内容,我暂时还没有读懂,明白了再与各位分亨。初试qmake感到还是很强大,但也很易用的,比bakefile要易入门些。

阅读书: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.)

免责声明:文章转载自《Qt使用笔记(2)--Qmake的使用》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇java调用kettle_实现(2)改变websphere默认jdk为1.5下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

statement与preparedStatement 批量操作(转)

原文:http://blog.csdn.net/etttttss/article/details/16819547 PreparedStatement: 1) addBatch()将一组参数添加到PreparedStatement对象内部。 2) executeBatch()将一批参数提交给数据库来执行,如果全部命令执行成功,则返回更新计数组成的数组。 S...

本人学习Makefile的总结和分享

其实吧,习惯了IDE之后,很不喜欢自己来写makefile,而且刚学Makefile,感觉语法看起来挺简单的,编写起来也不是很难,但似乎要真正自己写起来就使不上力了 然后就一直找原因,在网上找文档,找教程,处于这个阶段无助的时候只有谷歌可以帮助了 分析得出,自己对编译的过程不熟悉,为什么要用那些编译命令不熟悉,对Makefile的理解不深 刚开始看 陈皓...

makefile中的自动化变量 【转】

转自:http://blog.chinaunix.net/uid-28458801-id-3495215.html 自动化变量 模式规则中,规则的目标和依赖文件名代表了一类文件名;规则的命令是对所有这一类文件重建过程的描述,显然,在命令中不能出现具体的文件名,否则模式规则失去意义。那么在模式规则的命令行中该如何表示文件,将是本小节的讨论的重点。 假如你需要...

bat脚本学习

bat 计算机系统文件类型    学习。 批处理文件,在DOS和Windows(任意)系统中,.bat文件是可执行文件,由一系列命令构成,其中可以包含对其他程序的调用。这个文件的每一行都是一条DOS命令(大部分时候就好像我们在DOS提示符下执行的命令行一样),你可以使用DOS下的Edit或者Windows的记事本(notepad)等任何文本文件编辑工具创建...

windows命令行(DOS批处理)添加任务计划

windows命令行(DOS批处理)添加任务计划   https://www.cnblogs.com/siyunianhua/p/10281082.html   1、开始按钮上右键选择【运行】。   2、输入cmd打开命令提示符。   3、执行schtasks可查看系统中的计划任务。   4、schtasks有很多参数,而且都是自然语参数。   5、用户可...

uboot学习之二----主Makefile学习之四----两种编译方法:原地编译和单独输出文件夹编译

第57-123行: 57 # 58 # U-boot build supports producing a object files to the separate external 59 # directory. Two use cases are supported: 60 # 61 # 1) Add O= to the mak...