在 Windows 上的 Qt 可执行文件中设置应用程序信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2784697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:18:07  来源:igfitidea点击:

Setting application info in a Qt executable file on Windows

windowsresourcesqt4versionversioninfo

提问by Martin Beckett

Anyone have an tips on setting the application info (ie. right click on .exe->properties) from Qt?

任何人都有关于从 Qt 设置应用程序信息(即右键单击 .exe-> 属性)的提示?

I can add arbitrary version strings to Qt resource file (qrc) and display them. But most Windows installers check the version number and I can't find a Qt way of setting these fields other than manually maintaining a separate .RC file

我可以将任意版本字符串添加到 Qt 资源文件 (qrc) 并显示它们。但大多数 Windows 安装程序检查版本号,除了手动维护单独的 .RC 文件外,我找不到设置这些字段的 Qt 方式

Some way that lets you update this from an automated build would also be nice!

让您从自动构建更新它的某种方式也很好!

回答by Jake Petroules

Here's how I do it... add a file called resources.rc to your project with the contents:

这是我的做法...将一个名为 resources.rc 的文件添加到您的项目中,内容如下:

IDI_ICON1   ICON    DISCARDABLE "res/app.ico"

#include <windows.h>
#include "version.h"

VS_VERSION_INFO VERSIONINFO
FILEVERSION     VER_FILEVERSION
PRODUCTVERSION  VER_PRODUCTVERSION
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904E4"
        BEGIN
            VALUE "CompanyName",        VER_COMPANYNAME_STR
            VALUE "FileDescription",    VER_FILEDESCRIPTION_STR
            VALUE "FileVersion",        VER_FILEVERSION_STR
            VALUE "InternalName",       VER_INTERNALNAME_STR
            VALUE "LegalCopyright",     VER_LEGALCOPYRIGHT_STR
            VALUE "LegalTrademarks1",   VER_LEGALTRADEMARKS1_STR
            VALUE "LegalTrademarks2",   VER_LEGALTRADEMARKS2_STR
            VALUE "OriginalFilename",   VER_ORIGINALFILENAME_STR
            VALUE "ProductName",        VER_PRODUCTNAME_STR
            VALUE "ProductVersion",     VER_PRODUCTVERSION_STR
        END
    END

    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1252
    END
END

and a file called version.h with the contents:

和一个名为 version.h 的文件,内容如下:

#ifndef VERSION_H
#define VERSION_H

#define VER_FILEVERSION             1,0,0,0
#define VER_FILEVERSION_STR         "1.0.0.0
VERSION = 0.4.0.1
QMAKE_TARGET_COMPANY = company
QMAKE_TARGET_PRODUCT = product
QMAKE_TARGET_DESCRIPTION = description
QMAKE_TARGET_COPYRIGHT = copyright
" #define VER_PRODUCTVERSION 1,0,0,0 #define VER_PRODUCTVERSION_STR "1.0##代码##" #define VER_COMPANYNAME_STR "Your Organization" #define VER_FILEDESCRIPTION_STR "CoolApplication" #define VER_INTERNALNAME_STR "CoolApplication" #define VER_LEGALCOPYRIGHT_STR "Copyright ? 2010 Your Organization" #define VER_LEGALTRADEMARKS1_STR "All Rights Reserved" #define VER_LEGALTRADEMARKS2_STR VER_LEGALTRADEMARKS1_STR #define VER_ORIGINALFILENAME_STR "coolapplication.exe" #define VER_PRODUCTNAME_STR "CoolApplication" #define VER_COMPANYDOMAIN_STR "example.org" #endif // VERSION_H

and lastly to your .pro file, add: RC_FILE = resources.rc. Non-Windows platforms will ignore the value so you needn't prefix it with win32:.

,最后你的.pro文件,添加:RC_FILE = resources.rc。非 Windows 平台将忽略该值,因此您无需在它前面加上win32:.

回答by peter.slizik

Okay, two years after being asked... but maybe somebody will find it useful...

好吧,在被问到两年后......但也许有人会发现它很有用......

Try to use the following qmake variables:

尝试使用以下 qmake 变量:

##代码##

More info here.

更多信息在这里