具有Qt的项目中的版本号 [英] Version Numbers in a project with Qt

查看:767
本文介绍了具有Qt的项目中的版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在整个项目中都需要版本号;在安装程序,代码,工具链等中.我不喜欢重复.我希望将版本号存储在一个中央权威位置.

Version numbers are needed all over a project; in installers, code, toolchains etc. I despise duplication. I want my version numbers to be stored in one central authoritative location.

我正在使用C/C ++,并在各种平台上使用Qt.在Qt中,qmake项目指定的版本号如下:

I am working with C/C++ and using Qt on various platforms. In Qt, qmake projects specify version numbers like:

VERSION = 1.2.3

在代码中,我使用类似于Version.h这样的标题:

In code I use something like in a header like Version.h:

#define VERSION_MAJ 1
#define VERSION_MIN 2
#define VERSION_REV 3
#define VERSION_STRING \"VERSION_MAJ\" "." \"VERSION_MIN\" "." \"VERSION_REV\"

我的安装程序工具链支持C预处理,因此我可以使用Version.h中指定的相同版本.但是,我不知道如何使qmake使用相同的版本号.我以为可以对pro文件进行预处理,但这不能工作,因为#个字符表示对pro文件的注释,C预处理程序将崩溃.

My installer toolchain has support for C preprocessing so I can use the same version specified in Version.h. However, I don't know how to get qmake to use the same version number. I thought I could preprocess the pro file, but that won't work as # characters mean a comment in pro files and the C preprocessor will fall over.

有人知道保持我的版本号集中的好方法吗?

Anyone know of a good way to keep my version number centralised?

推荐答案

如果希望将版本号存储在ac头文件中,则可以这样做,然后将其导入到项目文件中的Qt项目变量中.像下面这样的东西应该起作用:

If you want to be able to store your version numbers in a c header file, you can do so and then import them into the Qt project variables in the project file. Something like the below should work:

Version.h:

Version.h:

#define MY_MAJOR_VERSION 3
#define MY_MINOR_VERSION 1

.pro

HEADERS  += Version.h

VERSION_MAJOR = MY_MAJOR_VERSION
VERSION_MINOR = MY_MINOR_VERSION

这种方法的优点是,如果需要从Qt编译项目的其他部分,则可以使用权威的头文件.

The advantage of doing it this way round is that you can then use your authoritative header file if you need to compile other parts of the project away from Qt.

这篇关于具有Qt的项目中的版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆