-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'

Dau
  • 8,578
  • 4
  • 23
  • 48

2 Answers2

3

Your problem is probably that you are including myicon.rc as a regular file, and it is listed as a source file. It should not be listed there nor under headers, because it isn't going through the normal compiler. You do need to list it as RC_FILE = myapp.rc.

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

Note that ICON in .pro is only used on mac.

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

I've included sample code for how I typically handle my rc file, a version file, and how it gets used in main.cpp and in the .pro file.

This should work in Qt Creator and Visual Studio.

Here are the files I use when I am doing versioning and icons in 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

version.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

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

And lastly when creating icons, I usually use Gimp, making them at least 256x256 and then exporting them at different sizes using Phoca Save Icons. Other times I'll just make an png and then use something from here.

Hope that helps.

phyatt
  • 18,472
  • 5
  • 61
  • 80
  • Thanks for the suggestion. But getting the same error, and "mingw32-make[1]: *** No rule to make target '../Test/myicon.rc', needed by 'release/myicon_res.o'. Stop." What is that mean?? – Ashish Chauhan Jul 29 '15 at 23:15
  • I guess there is some problem in qt creater kit while deploying/building the project. any suggestions??? – Ashish Chauhan Jul 29 '15 at 23:18
  • Try a build clean, and deleting the Make.release and the Make.deploy files. That usually fixes some lingering problems after changing the .pro file. – phyatt Jul 29 '15 at 23:35
  • now one more error , release is not happening giving error "The program has unexpectedly finished", if i did not involve the icon and all that stuff, the program is building successfully, and i am still getting that "icon" error ,tried lot of stuffs already. :( – Ashish Chauhan Jul 29 '15 at 23:50
  • I did that many times "Try a build clean, and deleting the Make.release and the Make.deploy files. That usually fixes some lingering problems after changing the .pro file." – Ashish Chauhan Jul 29 '15 at 23:51
0

Mingw does not know how to handle a .rc file.

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

Mark Jansen
  • 1,491
  • 12
  • 24