Using projects version information from source code
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.
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
# 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\\\"
# In Symbian the syntax is little bit different.
DEFINES += APP_VERSION=\"$$VERSION\"
int main(int argc, char *argv)
QApplication app(argc, argv);
// Set the version number for the application.
// 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()));
The snippet demonstrated how to resolve the version number defined in .pro file in source code.