×
Namespaces

Variants
Actions

Using projects version information from source code

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Compatibility
Platform(s): Windows, Symbian
Symbian
Article
Keywords: Version info
Created: kratsan (30 May 2011)
Last edited: hamishwillee (11 Oct 2012)

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.

This page was last modified on 11 October 2012, at 04:18.
21 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×