Handling the program version with Qt, part 1

Usually your program has a version number (e.g. like 1.2.3) and you want to work with that number inside your program without changing that number in more than one file.

With Qt you configure your program with .PRO files which are a recipe for qmake the meta compiler that adds the Qt magic to your code. Both understand a variable called VERSION, that's the sunny part. On the dark side is the handling of it. At least on OSX there is none :-/

But it's quite easy to sneak a peak on that number from inside your program. While we are at it, we also add the git hash. Just add

VERSION = 1.2.3
macx:HC_GITHASH  = $$system(git show HEAD|grep "^commit"|cut -c 8-)
# define c style macros to access the following values from inside the program

to your .PRO file and that will result into two #define statements, or C-style macros in other words. Not perfect, because the compiler can't do type checking. On the other hand you're the boss and can handle those two values responsibly.

One question remains: how do we get this number into the application bundle (still talking OSX here), so that the user can right click (or CTRL-click) with the Finder and chose get info?.