[Qt-interest] application version and DRY principle

Dmitry Teslenko dteslenko at gmail.com
Fri Feb 18 13:18:49 CET 2011


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 probably meant QCoreApplication::setApplicationVersion(QString) - right?

Yes, you are right. Thanks.


-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?



More information about the Qt-interest-old mailing list