1
votes

I've been struggling with adding an icon to my QT application. Now the problem is not getting it to work in the application itself (the icon shows fine in both the taskbar and in the upper left of the application window). The issue is with the windows explorer.

Now I found a few solutions which state to either add an .rc file to the .pro file or to use RC_ICONS. But both of these implementations result in a linker error:

LNK1123: failure during conversion to COFF: file invalid or corrupt

Doing some search onto that only resulted in finding people that try to compile without having VS2010 installed, but that's not the case here since it is installed and compiles fine without the icon.

Any suggestions would be appreciated.

1

1 Answers

1
votes

The following solution worked for me with both Visual C++ 2013 and MinGW but this is Windows-specific.

Add the following line to your Qt project file.

RC_FILE = WindowsResource.rc

Now create a text file in the same folder as your Qt project file and call it WindowsResource.rc, you can call it whatever you want as long as it is referenced correctly in the Qt project file. Open it in Notepad and insert the following line.

IDI_ICON1 ICON DISCARDABLE "MyIcon.ico"

Now place the icon you want in the same folder as your Qt project file and call it MyIcon.ico, you can call it whatever you want as long as it is referenced correctly in the windows resource file you created.

Run qmake and rebuild your application, the .exe file should now show up in Windows Explorer with the new icon.

Edit: I used Visual C++ 2013 and it worked. I quote the article at http://support.microsoft.com/kb/2757355

Cause: This error can appear after installing Visual Studio 2012 side-by-side (SXS) with Visual Studio 2010 RTM or after installing .Net Framework 4.5 on a machine with Visual Studio 2010.

Resolution: To resolve this link error, upgrade Visual Studio 2010 RTM to VS 2010 SP1. Upgrading to VS 2010 SP1 resolves the dependency failure and the VC++ 2010 project builds with no LNK1123 error.

If you are using Visual C++ 2010 then I suggest that you make sure you have Service Pack 1 installed, I'm not sure that installing SP1 would solve the issue though because you were compiling fine without the icon.