Qt的.自动添加应用程序版本

syn*_*ker 12 qt qmake

.pro文件中,我可以设置应用程序的版本:

VERSION = <some version>
Run Code Online (Sandbox Code Playgroud)

有没有办法自动执行此操作(例如从Mercurial获取值)?

ale*_*sdm 7

如果您可以从shell命令获取版本,则可以使用$$systemqmake函数将其分配给变量.

所以,对于mercurial,你可以尝试:

# if the version tag is <major version>.<minor version> 
VERSION = $$system(hg parents --template '{latesttag}.{latesttagdistance}')
# or if you fill all 3 positions manually: <major>.<minor>.<patchset>
VERSION = $$system(hg parents --template '{latesttag}')
Run Code Online (Sandbox Code Playgroud)

或者,如果您使用本地修订号作为版本:

VERSION = $$system(hg parents --template '{rev}')
Run Code Online (Sandbox Code Playgroud)

只会在没有未提交的更改指示符('+')的情况下打印该数字.