Namespaces
Variants
Actions

Using projects version information from source code

Jump to: navigation, search
Knowledge base identifier with text.png
Warning.png
Warning: This is not a protected Knowledge Base entry. Please treat it with caution.
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.

Comments

(no comments yet)

This page was last modified on 24 June 2011, at 09:30.
102 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2012 All rights reserved