qtvisual-studio-2019application-icon

How to make setWindowIcon work properly in a stand-alone executable (Qt5.14 + VS2019)?


I am programming a Qt application in MS Visual Studio Community 2019. I am trying to add an icon to my application window with the following command, and I also have the corresponding file my_icon.ico mentioned in the .qrc file:

setWindowIcon(QIcon(":/my_icon.ico"));

When I build and run my program in VS, everything is perfect - the icon replaces the standard one. However, when I make a release and try to run the resulting stand-alone executable, the icon is NOT shown! This is particularly weird as images which I also mention in the .qrc file (pictures for buttons) are on their places.

I have tried to put my_icon.ico alongside the .exe file, but with no result.

I give up, please give me a clue what might be happening here.


Solution

  • Thanks to chehrlic, I understood that it was as simple as running the windeployqt.exe on the .exe file build by the Release configuration by Visual Studio.

    This will link all required libraries dynamically.

    Avoid using this tool while the .exe file is inside the Release folder as it will create many other files & folders near .exe file. I have copied my_app.exe to a fresh directory and ran the following command from it:

    C:\Qt\5.14.1\msvc2017_64\bin\windeployqt.exe my_app.exe --release
    

    See https://doc.qt.io/qt-5/windows-deployment.html for more details.