How do I set my application version for Windows in Qt?
Asked Answered
G

3

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.

Grownup answered 6/4, 2017 at 17:8 Comment(0)
S
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.

Selfdiscipline answered 6/4, 2017 at 17:27 Comment(4)
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.Grownup
@Grownup 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.Selfdiscipline
Perfect. Thank you! The need to migrate to Qt5 is becoming more and more apparent, even with a QWidget application.Grownup
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.Hardej
I
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

Inoffensive answered 12/11, 2021 at 9:58 Comment(0)
N
2

Use the QCoreApplication class.

QCoreApplication::setApplicationVersion("1.0");
Nolitta answered 15/10, 2020 at 7:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.