Search code examples
qticonsqt-designer

Qt Main Window not loading its icon


I am using Qt 4.8.4 and I have created a QMainWindow using Qt Designer, so my .ui file generates the corresponding ui_....h file. I have the corresponding .qrc with the correct icon inside, and I can see it when I preview my window using Qt Designer. At the end, when loading the application, the window does not have any icon, just the default Windows application icon.

I am using Visual Studio 2010 to compile the project. Thus, I am not using any '.pro' file. Here is the code of the .vcxproj that compiles the Qt resource file:

<CustomBuild Include="dlgConnect.qrc">
  <FileType>Document</FileType>
  <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(FullPath);%(AdditionalInputs)</AdditionalInputs>
  <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Rcc%27ing %(Identity)...</Message>
  <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\qrc_%(Filename).cpp;%(Outputs)</Outputs>
  <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"..\..\..\..\Software\QtSDK\Desktop\Qt\4.8.4\bin\rcc.exe" -name "%(Filename)" -no-compress "%(FullPath)" -o .\GeneratedFiles\qrc_%(Filename).cpp</Command>
  <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(FullPath);%(AdditionalInputs)</AdditionalInputs>
  <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Rcc%27ing %(Identity)...</Message>
  <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\GeneratedFiles\qrc_%(Filename).cpp;%(Outputs)</Outputs>
  <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"..\..\..\..\Software\QtSDK\Desktop\Qt\4.8.4\bin\rcc.exe" -name "%(Filename)" -no-compress "%(FullPath)" -o .\GeneratedFiles\qrc_%(Filename).cpp</Command>
</CustomBuild>

It seems to be correct but I have no successful result.

Does anybody experienced the same?

Cheers,


Solution

  • You need this in your .pro file

    RC_FILE += Icon.rc
    

    and you need this in your Icon.rc file

    IDI_ICON1   ICON   DISCARDABLE   "./MyIcon.ico"
    

    and you need the MyIcon.ico icon file.