9

When my application crashes, the Windows Event Viewer always reports my application version as "0.0.0.0". Windows Event Viewer version I can't figure how to set the application version in a way that the Windows Event Viewer recognizes. Changing it with QApplication::setApplicationVersion() doesn't seem to do it.

Obviously there are better ways to debug a program than the Windows Crash Log, but in lieu of all of that, how would I go about setting this value so that Windows recognizes it? My IDE is Qt Creator.

3 Answers 3

9

You can set the VERSION qmake variable in your pro file:

VERSION = 1.0.0.0

On Windows, triggers auto-generation of an .rc file if the RC_FILE and RES_FILE variables are not set. The generated .rc file will have the FILEVERSION and PRODUCTVERSION entries filled with major, minor, patch level, and build number.

4
  • 1
    This is exactly right. However, it doesn't work when setting the app icon as instructed here because that'll override the rc file created by VERSION. Is there a way to combine these two RC files? RC_FILE += doesn't appear to have the desired effect.
    – Phlucious
    Commented Apr 6, 2017 at 19:07
  • 2
    @Phlucious In Qt 5 there is a handy RC_ICONS qmake variable, however I'm not sure if it is available in Qt 4. If not, you can always manually combine the contents of both RC files and into a single one and refer to it using RC_FILE.
    – kefir500
    Commented Apr 6, 2017 at 19:40
  • Perfect. Thank you! The need to migrate to Qt5 is becoming more and more apparent, even with a QWidget application.
    – Phlucious
    Commented Apr 6, 2017 at 20:05
  • For me, usage of the RC_FILE variable because VERSION does not override the RC_FILE but instead RC_FILE just causes VERSION to not work. I can confirm that using RC_ICONS instead of RC_FILE fixed everything for me. Commented Mar 24, 2020 at 19:47
5

If you develop a widget app or qml, maybe you want to show your version in WindowTitle.

A full solution would be:

In .pro file add:

VERSION = 1.2.3
DEFINES += APP_VERSION=\\\"$$VERSION\\\"

and in QWidget or QMainWindow:

setWindowTitle("Qt " +qtVersion + " Version"+ APP_VERSION);

or in QML:

ApplicationWindow {
    title: "Qt " +qtVersion + " Version"+ APP_VERSION
...

enter image description here

2

Use the QCoreApplication class.

QCoreApplication::setApplicationVersion("1.0");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.