如何在 Qt 中为 Windows 设置我的应用程序版本?

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

当我的应用程序崩溃时,Windows 事件查看器总是将我的应用程序版本报告为“0.0.0.0”。 我不知道如何以 Windows 事件查看器识别的方式设置应用程序版本。用 QApplication::setApplicationVersion() 更改它似乎不起作用。

显然有比 Windows 崩溃日志更好的调试程序的方法,但是除了所有这些之外,我将如何设置这个值以便 Windows 识别它?我的 IDE 是 Qt Creator。

您可以在 pro 文件中设置 VERSION qmake 变量:

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.

使用 QCoreApplication class.

QCoreApplication::setApplicationVersion("1.0");

如果您开发小部件应用程序或 qml,也许您想在 WindowTitle 中显示您的版本完整的解决方案是: 在 .pro 文件中添加:

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

并在 QWdigetQMainWindow

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

QML

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