0

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.

udavdasha
  • 79
  • 1
  • 6
  • How do you deploy your application? Please use windeployqt - then the plugin for the ico image format is properly copied to the correct location and the image can be loaded. – chehrlic Mar 31 '20 at 04:39
  • It turns out I am pretty new in this, as before I programmed only rather simple console soft. What I do now is I just build a release version in Visual Stidio, then I go to the Release directory and I copy the .exe file to a fresh folder. Surely it was annoyed by the absence of Qt libraries which I gave to it manually by copy&paste from Qt folder. – udavdasha Mar 31 '20 at 12:02
  • Could you clarify where should windeployqt enter this pipeline? As far as I got from this documentation (https://doc.qt.io/qt-5/windows-deployment.html), I should configure the whole Qt to be static (as my dream is to have all libraries inside my .exe) and then feed the Release folder to windeployqt program. Am I right or do I miss something important? – udavdasha Mar 31 '20 at 12:02
  • 1
    How do you currently deploy your app? Simply by copying the exectuables + dlls? Don't do this but use windeployqt as described in the documentation. I would not use static linking in this early stage of knowledge. Esp. since it does not give you much - creating a proper installer is the much better way to go. – chehrlic Mar 31 '20 at 14:17

1 Answers1

0

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.

udavdasha
  • 79
  • 1
  • 6