Using projects version information from source code
Article Metadata
Compatibility
Platform(s): Windows, Symbian
Article
Keywords: Version info
Created: kratsan
(20 May 2011)
Last edited: hamishwillee
(24 Jun 2011)
Contents |
Overview
This snippet shows how to retrieve version information, defined in .pro file, from source code.
This decreases the chance of forgetting to update the version information to multiple places such as about box, info view etc. Instead, we have only one place in the project where the version number is defined.
myapp.pro
QT += core gui
TARGET = myapp
TEMPLATE = app
# The one and only place where to define the version number of the application.
VERSION = 1.0.0
SOURCES += main.cpp
win32 {
# Create a define APP_VERSION and set its value to our version.
# The APP_VERSION will be visible to the source code side.
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
}
symbian {
# In Symbian the syntax is little bit different.
DEFINES += APP_VERSION=\"$$VERSION\"
}
main.cpp
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Set the version number for the application.
app.setApplicationVersion(APP_VERSION);
// The version number can be now accessed anywhere on the code via QApplication instance.
// If we don't see the app variable, then we can get the QApplication instance via
// qApp macro.
QLabel *label = new QLabel(QString("Version: %1").arg(app.applicationVersion()));
label->show();
return app.exec();
}
Postconditions
The snippet demonstrated how to resolve the version number defined in .pro file in source code.



(no comments yet)