繁体   English   中英

Qt Gui应用程序图标设置

[英]Qt Gui Application icon setup

我想为我的qt gui应用程序设置一个图标,然后按照以下步骤操作:

 1. create an ICO file bitmap That contains the icon image.
 2. Store the ICO file in app's source code directory.
 3. create a text file and added these lines "IDI_ICON1 ICON DISCARDABLE
 4. myicon.ico" and saved it as "myicon.rc".
 5. and added these lines in my .pro file "RC_FILE = MYICON.RC"

但是它给出了这个错误:

mingw32-make [1]: *'debug / myicon_res.o'不需要创建目标'../Test/myicon.rc'的规则。 停止。 mingw32-make:* [调试]错误2 02:15:41:进程“ C:\\ TDM-GCC-32 \\ bin \\ mingw32-make.exe”以代码2退出。构建/部署项目测试(套件时出错) :桌面)执行步骤“制作”时

您的问题可能是您将myicon.rc作为常规文件包括在内,并且被列为源文件。 它不应在此处或标题下列出,因为它不会通过常规编译器。 您确实需要将其列出为RC_FILE = myapp.rc

http://doc.qt.io/qt-5/qmake-variable-reference.html#rc文件

请注意,.pro中的ICON仅在Mac上使用。

http://doc.qt.io/qt-5/qmake-variable-reference.html#icon

我已经提供了示例代码,说明了我通常如何处理rc文件,版本文件以及如何在main.cpp.pro文件中使用它们。

这应该可以在Qt Creator和Visual Studio中使用。

这是我在Windows中进行版本控制和使用图标时使用的文件:

myapp.rc

// http://stackoverflow.com/questions/2784697/setting-application-info-in-qt
#include <windows.h>
#include "version.h"

// if you needed to maintain two different icons for your app, you could
// switch here using a #ifdef and #else
#define MYICON "my_icon.ico"

IDI_ICON1               ICON    DISCARDABLE     MYICON

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

版本

#ifndef VERSION_H
#define VERSION_H

#define VER_FILEVERSION             0,1,0,0
#define VER_FILEVERSION_STR         "0.1.0.0\0"

#define VER_PRODUCTVERSION          15,07,01,50
#define VER_PRODUCTVERSION_STR      "15.07.01.50"

#define VER_COMPANYNAME_STR         "MySoft"
#define VER_FILEDESCRIPTION_STR     "Star Runner"

#define VER_INTERNALNAME_STR        "Star Runner"
#define VER_LEGALCOPYRIGHT_STR      "Copyright © MySoft"
#define VER_LEGALTRADEMARKS1_STR    "All Rights Reserved"
#define VER_LEGALTRADEMARKS2_STR    VER_LEGALTRADEMARKS1_STR
#define VER_ORIGINALFILENAME_STR    "star_runner.exe"
#define VER_PRODUCTNAME_STR         "Star Runner"

#define VER_COMPANYDOMAIN_STR       "mysoft.com"

#endif // VERSION_H

main.cpp

#include <QApplication>
#include "version.h"
#include <QSettings>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    a.setApplicationName(VER_PRODUCTNAME_STR);
    a.setOrganizationName(VER_COMPANYNAME_STR);
    a.setOrganizationDomain(VER_COMPANYDOMAIN_STR);
    a.setApplicationDisplayName(VER_PRODUCTNAME_STR);
    QSettings::setDefaultFormat(QSettings::IniFormat);

    // Create the widget or main window here

    return a.exec();
}

star_runner.pro

# all sorts of other things like SOURCES and HEADERS and FORMS, etc.
# ...

win32 {
    # DEFINES -= UNICODE
    RC_FILE += myapp.rc
}

macx {
    ICON = my_icon.icns
}

OTHER_FILES += \
    my_icon.ico \
    my_icon.icns \
    myapp.rc

最后,当创建图标时,我通常使用Gimp,使它们至少为256x256,然后使用Phoca Save Icons导出为不同大小。 其他时候,我只是制作一个png,然后从这里使用一些东西。

希望能有所帮助。

Mingw不知道如何处理.rc文件。

请参阅: http//www.mingw.org/wiki/MS_resource_compiler

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM