12

In a .pro file, I can set version of application such:

VERSION = <some version>

Is there a way of doing this automatically (e.g. getting the value from Mercurial)?

tshepang
  • 12,111
  • 21
  • 91
  • 136
synacker
  • 1,722
  • 13
  • 32

1 Answers1

7

If you can get the version from a shell command, you can assign it to the variable with the $$system qmake function.

So, for mercurial, you could try:

# 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}')

Or if you are using the local revision number as the version:

VERSION = $$system(hg parents --template '{rev}')

which will only print that number without the uncommitted change indicator ('+').

alexisdm
  • 29,448
  • 6
  • 64
  • 99
  • Thanks. But exist more easy solution. You can use $$system($$(PWD)/hg id -n). In this case will return version number of repository. But the problem is that the mercurial can return the number with the symbol "+". This is an invalid character in the version number. – synacker May 13 '12 at 06:55
  • @Milovidov You can get rid of '+' with the help of `replace()`: `VERSION = $$replace(VERSION, "+", "")` – Bill May 13 '12 at 08:54
  • 1
    @Milovidov You can use a template too for only returning the number part (I edited the answer). – alexisdm May 14 '12 at 11:49
  • Worked for me a long time until I have installed VS2012. Then it started to fail with COFF-error as described in http://stackoverflow.com/questions/14139685/qt-after-installation-of-vs2012-lnk1123-failure-during-conversion-to-coff Maybe someone has an idea. – Horst Walter Jan 05 '13 at 11:45