This post is NOT about the application version number format to use, instead in this post I would be concentrating how to set and use the application version number information in a Qt project.
If this post is on any use to you, please leave a comment.
First way: Defining the version information within the application source code
The application version can be set as through the string constant or preprocessor Macro defined in some header file.
I have used this method many times before.
Also, here once you create the QApplication object, you can set this application version to QApplication object and ignore this constant/Macro defined from then on. Whenever you need the application version you can directly get it from qApp global QApplication object.
You can use following APIs
- QString applicationVersion()
- void setApplicationVersion(const QString & version)
You can use Qt QMake Macro named VERSION to define the Application version.
VERSION = 1.0
The good thing with this QMake Macro is that, it automatically creates the .rc file under Microsoft Windows and you can see the application version number from Windows Explorer by right clicking on the executable.
What I do is that, I use preprocessor Macro defined through Qt project file to pass application version number to code.
# The application version
VERSION = 1.0
# Define the preprocessor macro to get the application version in our application.
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
Note: \\\" is important! Without them, the Macro is taken as a double constant instead of string constant.
Now use the Macro APP_VERSION in your code just like any other preprocessor Macro.
QApplication app(argc, argv);
// Setting the Application version
Similarly you can set the Application date also.
You can browse the sample Qt project @ My Google code page.
Technorati tags: OpenGuru.org weblog, Qt, Application version.