-1

I want to setup an icon for my qt gui application , and followed the steps listed below:

 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"

but it is giving this error:

mingw32-make[1]: * No rule to make target '../Test/myicon.rc', needed by 'debug/myicon_res.o'. Stop. mingw32-make: * [debug] Error 2 02:15:41: The process "C:\TDM-GCC-32\bin\mingw32-make.exe" exited with code 2. Error while building/deploying project Test (kit: Desktop) When executing step 'Make'

4

2 回答 2

3

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

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

请注意,ICONin .pro 仅在 mac 上使用。

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

我已经包含了关于我通常如何处理我的rc文件、版本文件以及它如何main.cpp.pro文件中使用的示例代码。

这应该适用于 Qt Creator 和 Visual Studio。

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

我的应用程序.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

版本.h

#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

主文件

#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,然后从这里使用一些东西。

希望有帮助。

于 2015-07-29T21:32:49.353 回答
0

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

见: http: //www.mingw.org/wiki/MS_resource_compiler

于 2015-07-30T07:49:30.333 回答