首先说一下qt编程的步骤,然后再仔细说一下qmake的使用。我看书上的都是编写好cpp文件后,分别执行命令: qmake -project、qmake、make,然后执行就可以了,但是要是我在一个文件夹下有多个cpp文件,qmake怎么识别?make生成的最后执行文件的名,我怎么能随心所欲的自己定?带着疑问,找了网上的资料,不如所衣,然后尝试着gcc编译的思想竟然撞到了。
其实我感觉要要真正了解qmake的使用方法,直接在终端下输入命令:qmake -help就可以了,我也是这样做的,帮助内容如下
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; *.H; *.cpp; *.cc; *.cxx; *.C
Note: The created .pro file probably will
need to be edited. For example add the QT variable to
specify what modules are required.
-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; specific ones may be re-enabled by
later -W options
-Wall Turn on all warnings
-Wparser Turn on parser warnings
-Wlogic Turn on logic warnings (on by default)
-Wdeprecated Turn on deprecation warnings (on by default)
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
-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
-set <prop> <value> Set persistent property
-unset <prop> Unset persistent property
-query <prop> Query persistent property. Show all if <prop> is empty.
-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]
song@ubuntu:~/lianxi/qt$ clear
song@ubuntu:~/lianxi/qt$ qmake -help
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; *.H; *.cpp; *.cc; *.cxx; *.C
Note: The created .pro file probably will
need to be edited. For example add the QT variable to
specify what modules are required.
-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; specific ones may be re-enabled by
later -W options
-Wall Turn on all warnings
-Wparser Turn on parser warnings
-Wlogic Turn on logic warnings (on by default)
-Wdeprecated Turn on deprecation warnings (on by default)
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
-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
-set <prop> <value> Set persistent property
-unset <prop> Unset persistent property
-query <prop> Query persistent property. Show all if <prop> is empty.
-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]
qmake命令格式
qmake [mode] [options] [files]
mode选项
-project 生成.pro文件
-makefile 生成Makefile文件
options选项(这里介绍几个常用的,其它的自己去翻译上面,其实我也是刚学,用到的时候再学习哈)
-o file 输出文件名,比如qmake -project hello.cpp -o hello.pro,就会生成一个hello.pro文件,如果是qmake -project hello.cpp -o hello11.pro,就会生成一个hello11.pro文件
实验1
1、编写代码,命名为hello.cpp,如下
hello.cpp代码如下
#include<qapplication.h>
#include<qpushbutton.h>
int main(int argc,char *argv[])
{
QApplication a(argc,argv);
QPushButton hellobtn("Hello World!",0);
hellobtn.resize(200,50);
hellobtn.show();
return a.exec();
}
2、qmake -project (用于创建.pro文件,将所有的文件编译成一个与平台无关的工程文件)
可见默认生成的文件名为 qt.pro
3、qmake (读取本身的Qt设置,生成与库一致的相应的Makefile)
4、make (根据生成的Makefile,将文件编译为二进制可执行程序)
可见生成了qt可执行程序
5、执行命令:./qt
实验2
本实验中并没有用到上面所讲的方式,而是直接使用了默认值,但是假设说该文件夹下有两个cpp文件,如下图
这时候再执行命令:qmake -project会怎么样呢?会出现下面的结果
有点意思,竟然不出错,但是你知道它生成的qt.pro是哪个cpp文件的吗?我不知道,加入这里我想对test.cpp操作,这时候就要按照上面的格式了。
1、qmake -project test.cpp -o test.pro
这时候生成了test.pro
2、qmake -makefile test.pro,这里生成test.pro的Makefile
3、make
4、执行命令 ./test
分享到:
相关推荐
linux/unix 使用详解介绍,对初学者和Linux程序员都有用
安装某些软件是总是缺少一些库,这是我搜索的资源希望对你有用 qt4-qmake_4.4.3-1+lenny1_i386.deb
再在终端输入:zhuquan@zhuquan-HP-Z230-Tower-Workstation:~$ qmake -v显示结果为:QMake version
QT参考手册qmake手册Qt对象模型qt设计器等4个pdf文档
QT4学习资源,qmake-manual,英文版
qt4资源 和一些qmake .....和一些港湾网络的一个教学材料。。。哈哈
Qt+Cutelyst学习笔记(二十七)win10+Qt5.15.2+qmake实现一个简单的RESTful服务器 示例源码 https://blog.csdn.net/aggs1990/article/details/124115368 CSDN审核可能较慢,如无法下载,可以过段时间再回来看下
Qt+Cutelyst学习笔记(二十五)win10+Qt5.15.2+qmake实现一个简单的https服务器 示例源码 https://blog.csdn.net/aggs1990/article/details/124050267 CSDN审核可能较慢,如无法下载,可以过段时间再回来看下
交叉编译QT4.8.7源码生成qmake工具.pdf
Qt+Cutelyst学习笔记(二十八)win10+Qt5.15.2+qmake接收表单提交的文件 示例源码 https://blog.csdn.net/aggs1990/article/details/124128783 CSDN审核可能较慢,如无法下载,可以过段时间再回来看下
Qt+Cutelyst学习笔记(二十六)win10+Qt5.15.2+qmake实现一个简单的websocket服务器 示例源码 https://blog.csdn.net/aggs1990/article/details/124063275 CSDN审核可能较慢,如无法下载,可以过段时间再回来看下
Qt+Cutelyst学习笔记(二十四)win10+Qt5.15.2+qmake实现一个简单的http服务器 示例源码 https://blog.csdn.net/aggs1990/article/details/124047777 CSDN审核可能较慢,如无法下载,可以过段时间再回来看下
零基础学Qt4编程 第1 章走近Qt 第2 章Qt 的安装与配置 ...第10 章在程序中使用.ui 文件 第11 章布局管理 第12 章使用Qt Creator 第13 章Qt 核心机制与原理 附录A qmake 命令 附录B make 命令 附录C Qt 资源 参考文献
qmake的介绍 qmake是Trolltech公司创建的用来为不同的平台和编译器书写Makefile...Trolltech公司使用qmake作为Qt库和Qt所提供的工具的主要连编工具。 qmake也注意了Qt的特殊需求,可以自动的包含moc和uic的连编规则。
qt video,从基础开始,第2部分,一共14部分,使用vs2015的addin作为教学工具,很不错的。
从题而看,我们必须要明确的是qmake不仅仅是可以在QT中可以使用,在其他的情况下也可以使用。实际上qmake是一个帮助在不同平台上简化编译步骤的工具,她是来自Trolltech,qmake能够自动生成Makefile 使得只需要少量...
\蔡志明首次引入Qt设计器的使用,绘制并实现了一个查找文件功能的部件,介绍了Qt应用程序中使用ui文件的基本方法以及Qt样式表;较深入地分析了Qt对象模型的一些基本知识,涉及信号和槽机制、Qt元对象系统、属性系统...
这个是单独的qmake.exe工具,如果不想安装qt的相关的包仅仅想使用QT creator。
Qt开发的小游戏 ,无音效部分,源码上传,基于qt6.2下编译qmake Qt开发的小游戏 ,无音效部分,源码上传,基于qt6.2下编译qmake Qt开发的小游戏 ,无音效部分,源码上传,基于qt6.2下编译qmake Qt开发的小游戏 ,无音效...
qmake及QTCreator的使用教程