PDA

View Full Version : How to add the auto-"build number" in Qt Application?



Sambu
8th December 2011, 10:46
Hi All,

currently i am using follwoing code to reprasent SW version .
---------------
#define MajorNumber 11
#define MinorNumber 22
#define ReleaseNumber 33
#define BuildNumber 44
------------
Problem here is ,each and every time manualy changing these macro values(build number) to update the SW Version.

1)Is there anyway options in Qt, to auto update the build number in SW Version ?
In other worlds ,How to add the auto-"build number" in Qt Application?

Please guide me on the same.

Regards,
sambu.

Spitfire
8th December 2011, 10:55
One option would be to stick that define in separate file, then create a custom build step which would run a shell script (or your own command line tool) that incrementes the build number before the actual build takes place.

Lykurg
8th December 2011, 11:28
Maybe Version_numbering_using_QMake can help you.

Sambu
8th December 2011, 14:38
Hi Lykurg,

thanks for your replay.

Here ,i could not get any the Auto build number. i think,this is also similar to macro. here they declar a string in .pro file and reading the string in main.cpp file ,to print the version.
here ,if we build the application second time also same string will dispaly.
there is no provision for store the old version number.

can u sugest any onther way or can u provide any sample code ?

-----------------------
from :Version_numbering_using_QMake:

You can have automatic version numbering for libraries built using QMake. Consider the following example using SVN to get the current version (substitute it with a command that returns the version number for your project).

Add the following to your project file:

VERSION = $$system(svn info -r HEAD . | grep 'Changed\ Rev' | cut -b 19-)
!isEmpty(VERSION){
VERSION = 0.$${VERSION}
}You can also set a version for your application by adding:

VERSTR = '\\"$${VERSION}\\"' # place quotes around the version string.
DEFINES += VER=\"$${VERSTR}\" # create a VER macro containing the version stringThen you can use the "VER" macro in your application to obtain the quoted version number:

#include <QtGui/QApplication>
#include<QDebug>
#include "application.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qDebug("VERSION: %s :\n", VER);
return a.exec();
}
-------------------------

regards.
Sambu.

Added after 45 minutes:

Hi Spitefire,

Thanks for nice idea.

but how can we know before comple the application build process , whether it is build successful or fail to build ?
can you send any sample snipets for the same,if you have.

Regards,
Sambu.

Lykurg
8th December 2011, 16:26
Maybe I don't get you but
VERSION = $$system(svn info -r HEAD . | grep 'Changed\ Rev' | cut -b 19-) is querying dynamically the actual version from svn. You can alter that easily if you work with git or others.

Spitfire
8th December 2011, 17:26
Depends on where you want to implement it you need different approach.

If it's for automatic build system then Lykrug's idea is better.

But if it's for you to change the build number as you progress between commits to vcs, then you'll need to go with my suggestion (or something similar).

As to the failed builds - I wouldn't bother with that, as long as every build has a different number it shouldn't be a problem if it fails or not.