[Qt-interest] application version and DRY principle
Konstantin Tokarev
annulen at yandex.ru
Fri Feb 18 14:37:48 CET 2011
18.02.2011, 15:18, "Dmitry Teslenko" <dteslenko at gmail.com>:
> On Fri, Feb 18, 2011 at 14:50, Konrad Rosenbaum <konrad at silmor.de>; wrote:
>
>> On Fri, February 18, 2011 12:20, Dmitry Teslenko wrote:
>>> How to define application version once and use it everywhere:
>>> a) in *.pro file to set custom package name like Program-<version>
>> Have a look at the DEFINES variable of qmake (there is quite an extensive
>> reference for qmake in the Qt docu).
>>> b) in c++ sources to pass it to QApplication::setVersionNumber and
>>> have about dialog with version number
>> DEFINES get passed to the compiler, so you can put any kind of macro
>> inside, for example
>>
>> DEFINES += MYAPPVERSION="1.2.3 beta build 234"
>
> Did you use it for yourself or you just heard of defines?
>
> The way you suggest it me I'll get this makefile:
>
> DEFINES = -DMYAPPVERSION=1.2.3 beta build 234 -DSOMETHING_ELSE
>
> That's unusable makefile.
> If you add additional quotes like this:
>
> DEFINES += MYAPPVERSION="\"1.2.3 beta build 234\""
>
> You'll get right makefile. But you'll get syntax error in source code
> because when you type something like this:
>
> QApplication::setApplicationVersion(MYAPPVERSION);
>
> Compliler will get:
>
> QApplication::setApplicationVersion(1.2.3 beta build 234);
>
> and will complain. And he would be right.
You should pass \\\"1.2.3 beta build 234\\\", it will pass escaped quoted string into the macro
--
Regards,
Konstantin
More information about the Qt-interest-old
mailing list