3

Considering this: http://www.openguru.com/2009/11/qt-best-way-to-set-application-version.html

I have added VERSION = 1.0 in the .pro file of my Qt project which is currently running
on Ubuntu 12.04.4 LTS with the desktop environment LXDE.

Cleaned, qmaked, builded again, but now the question is how to see the version information.

When I right click the executable, I can see the following fields only:
Type, Size, Location, MIME Type, Modified, Owner, Part of, Permissions

How to see the version information now?

Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
  • For windows there is http://stackoverflow.com/questions/2784697/setting-application-info-in-qt using the resource file for detailed information, does the version eventually get shown as information bubble? Does LXDE show version on native applications? – Sebastian Lange Jul 16 '14 at 05:50
  • @SebastianLange I already saw lots of Windows threads. I want this on Linux. No, I checked LXDE does not show version info on native apps also. That's why I added the word "see" in the title. – Aquarius_Girl Jul 16 '14 at 05:55
  • 1
    Probably thats a missing LXDE feature then? Try running another WM at :8 like KDE/Gnome and check if these show the version information in tooltip or application properties. Not sure if version information is supported as in windows properties at all. – Sebastian Lange Jul 16 '14 at 06:00

3 Answers3

9

There is no standard way of getting version information from applications on Linux systems. Often a --version command line switch is provided for this purpose. But there's no freedesktop.org standard that would provide a more descriptive version information. The .desktop files don't contain such information - the version there is the file format version, not the application version.

So what you're seeking is simply not implemented. But if the --version was a sufficient interface, then here's how one could do it.

Your .pro file needs to contain both the version setting and pass the version to the C/C++ compiler:

VERSION = 1.0.0
DEFINES += VERSION_STRING=\\\"$${VERSION}\\\"

The version can be then shown from the command line by passing the --version argument. You can leverage the command line parser, available since Qt 5.2:

#include <QCoreApplication>
#include <QCommandLineParser>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    a.setApplicationName("version-cmd");
    a.setApplicationVersion(VERSION_STRING);
    QCommandLineParser parser;
    parser.addVersionOption();
    parser.process(a);
    return a.exec();
}

The output:

$ version-cmd --version
version-cmd 1.0.0
$

And if you don't use at least Qt 5.2, it's easy enough to check if a.args().contains("--version") and act on that.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • Thats probably what the op was waiting for. Good advice! Never used the .desktop files since my linux is more of embedded style not using X. Are these .desktop files supported in all (most) wm? – Sebastian Lange Jul 16 '14 at 06:22
  • @SebastianLange A window manager (wm) has a very specific meaning, it is not a synonym of a "desktop environment". When you're right clicking on a desktop icon, the window manager is merely shifting focus to the desktop application. The desktop application itself deals with it enumeration of desktop icons, right-click menus, etc. So it will depend on how your environment is set up, and what desktop application you're using. Most modern desktops do in fact use the `.desktop` files, or they simply don't support the notion of a "version" of an executable. – Kuba hasn't forgotten Monica Jul 16 '14 at 06:27
  • @TheIndependentAquarius Well, can you get version information on right click for *anything* in LXDE? If you do, what is it that you right-click on? The executable, or a link file? If the latter, you need a link file. – Kuba hasn't forgotten Monica Jul 16 '14 at 07:39
  • @KubaOber Actually, no, neither on Gnome nor on LXDE I have been able to see the version info for anything. – Aquarius_Girl Jul 16 '14 at 07:41
0

You can add command line switch --version to get application version

nib
  • 700
  • 8
  • 15
0

Now it is clear that there is no explicit version showing option list in the recognized desktop entry keys of www.freedesktop.org, but they do have other field(s) there which can be used to hold the version information.

One such field is GenericName.
This field gets listed as Description on GNOME desktop environment.

So, if I add version info in this field as follows:

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=excuse
Name[en_IN]=excuse
Exec=/usr/bin/bc
Comment[en_IN]=asdsadsad
StartupNotify=true
GenericName[en_IN]=Version 12.3
Icon=/usr/share/lxpanel/images/capslock-off.png

It gets shown on the right click as follows:

enter image description here

So, in a nutshell, we have the option to store our executable in /usr/bin/ where normal Linux executables are stored, and then create its shortcut on the desktop or somewhere else. Then we will be able to right click this shortcut and get the version information.

Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411