我创建了一个简单的rc文件并放入.pro
:
rcexample.rc
#include "winver.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGS 0x0L
FILEFLAGSMASK 0x3fL
FILEOS 0x00040004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000004b0"
BEGIN
VALUE "CompanyName", "Foo Bar CompanyName"
VALUE "FileDescription", "Foo bar FileDescription"
VALUE "FileVersion", "1.0.0.1"
VALUE "LegalCopyright", "Foo bar LegalCopyright"
VALUE "InternalName", "foobar"
VALUE "OriginalFilename", "foobar.exe"
VALUE "ProductName", "foobar product name"
VALUE "ProductVersion", "1.0.0.1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0, 1200
END
END
winvertest.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = winvertest
TEMPLATE = app
win32:RC_FILE = rcexample.rc # my rc file
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
main.cpp
#include <QDebug>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qDebug() << "applicationVersion:" << a.applicationVersion();
return a.exec();
}
使用 MSVC2015 32位,applicationVersion
返回:
applicationVersion:&#34; 1.0.0.1&#34;
但是使用 Mingw 5.3.0 会返回空:
applicationVersion:&#34;&#34;
这是一个Mingw问题还是Qt问题,还是我忘了在&#34; pro&#34;?
中添加一些内容?答案 0 :(得分:2)
您应该在其他地方定义版本号,并在.rc文件中使用这些定义。我为此使用了一个头文件src/appversion.h
,它包含:
#define MY_APP_VERSION "1.1.0"
/* MS Windows executable resource versions. */
#define W32_RC_FILEVERSION 1,1,0,00
#define W32_RC_PRODUCTVERSION 1,1,0,00
然后我在.rc文件中使用这些定义:
#include "src/appversion.h"
/* ... */
FILEVERSION W32_RC_FILEVERSION
PRODUCTVERSION W32_RC_PRODUCTVERSION
FILEFLAGSMASK 0x3fL
/* ... */
VALUE "FileVersion", MY_APP_VERSION
/* ... */
然后,在我实例化QApplication之后,我设置了这样的值:
a.setApplicationName(QString::fromLatin1("My App"));
a.setApplicationVersion(QString::fromLatin1(MY_APP_VERSION));