×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    9

    How to get an application version?

    I specified a version in my program pro file:
    VERSION=2.0.6
    How can my program get this version? QApplication::applicationVersion() returns an empty string.

    Version may be specified in code. Example:
    const char AppVersion[] = "2.0.6";
    QApplication::setApplicationVersion(AppVersion);
    But it is not conveniently to specify a version twice.

  2. #2
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,142

    Re: How to get an application version?

    As far as I know the version goes only to the instalaltion package, and it only used by the installer, thus its not really accessibe for the app itself once it has been installed.

  3. #3
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    600

    Re: How to get an application version?

    Actually it is accessible.
    Here is what i like to do:
    in my pro file i have the following
    VERSION = 1.5.0
    VERSTR = '\\"$${VERSION}\\"'
    DEFINES += VER=\"$${VERSTR}\"

    Then in my main.cpp file
    i can access that macro define VER as follow
    #if defined(Q_OS_SYMBIAN)
    // Workaround for an issue with Symbian: "X.Y.Z" -> X.Y.Z
    static const QString VERSION_NUMBER(QString("%1").arg(VER).mid(1, QString(VER).length()-2));
    #else
    static const QString VERSION_NUMBER(QString("%1").arg(VER)); // X.Y.Z by itself
    #endif
    (this handle both Symbian and Meego because of an old issue with String macro defines)
    Now you have VERSION_NUMBER as your static const of your app version number and you can set it to the QApplication or you can even pass it to a QML file like this:
    viewer->rootContext()->setContextProperty(QString("versionNumber"), VERSION_NUMBER);

  4. #4
    Registered User
    Join Date
    Feb 2013
    Posts
    9

    Re: How to get an application version?

    shai.i thank you. Your method works well on qt simulator.

    But in Nokia 5228 with Symbian the code:
    #if defined(Q_OS_SYMBIAN)
    static const QString VERSION_NUMBER(QString("%1").arg(VER).mid(1, QString(VER).length() - 2));
    #else
    static const QString VERSION_NUMBER(QString("%1").arg(VER));
    #endif
    QMessageBox::information(0, "LangTrainer", VERSION_NUMBER);
    shows .0. string.

    So I simply use VER definition to get version. Example:
    QMessageBox::information(0, "LangTrainer", VER);

    Why do you use QString("%1").arg(VER)? I seem it is simpler to use QString(VER) for VER to QString conversion. Perhaps strlen(VER) may be used instead of QString(VER).length().

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    600

    Re: How to get an application version?

    I dont remember why i used it like this, i do remember there was a bug invovling Qt creator and symbian which made the string to have the "" as well and it was needed to remove them from the string itself.
    If its working for you without the workaround then thats good.

  6. #6
    Registered User
    Join Date
    Feb 2013
    Posts
    9

    Re: How to get an application version?

    If VER may be in "X.Y.Z" form perhaps this is the good and short way to get version:
    QString VERSION_NUMBER((QString(VER).startsWith("\"") && QString(VER).endsWith("\"")) ?
    QString(VER).mid(1, strlen(VER) - 2) : VER);

  7. #7
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    600

    Re: How to get an application version?

    That might be better, anyway i'm glad i could help you discover how you can get the version number from your pro file to your code.

Similar Threads

  1. getting application version (sis version)
    By jose_yallouz in forum Symbian C++
    Replies: 1
    Last Post: 2010-03-29, 14:46
  2. How to get application version?
    By TacB0sS in forum Mobile Java General
    Replies: 1
    Last Post: 2009-11-15, 11:24
  3. Get application version
    By teelkee in forum Symbian C++
    Replies: 1
    Last Post: 2009-11-14, 12:31
  4. How to get application's version?
    By whasj35 in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2009-06-23, 09:20
  5. Replies: 1
    Last Post: 2003-03-24, 15:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •