[SOLVED] Display Icon in an .exe File in Qt
-
wrote on 13 Dec 2012, 12:45 last edited by
I am working on a Qt app where I need to display some UI and perform operation on them. When i run the application it creates a .exe in my debug/release folder. I want to put the icon in the .exe file rather than a blank icon which appears by default.
Is their a way one can do it in .ui file or we need to do it programmatically? I am kinda sure I need to use a resource file and store the image there. I tried to search for some more details but couldn't figure out anything related to Qt. Please help :)
-
wrote on 13 Dec 2012, 12:54 last edited by
"Setting the Application Icon":http://doc.qt.digia.com/qt/appicon.html
-
wrote on 13 Dec 2012, 13:11 last edited by
It's not clear what you want.
(1) Display an icon inside your window
(2) Change the window/taskbar icon of running application
(3) Change the EXE files icon, as shown in explorerSolutions:
(1) Use QIcon in conjunction with a QLabel and QLabel::setPixmap(). This can be done completely in the Qt Designer using a .ui file: Just add a QLabel and set its Pixmap property.
(2) Use QWidget::setWindowIcon(), again in conjunction with a QIcon.
(3) Not really in the scope of Qt. You need to add the icon as a resource to your EXE file, but not using Qt's resource system; use a Visual Studio .rc/.res file. -
wrote on 13 Dec 2012, 13:30 last edited by
[quote author="cincirin" date="1355403283"]"Setting the Application Icon":http://doc.qt.digia.com/qt/appicon.html[/quote]
The instructions in "Setting the Application Icon on Windows" surely is the right way but based from experience, it only works when using msvc2008 in Qt4.8.3 (mingw and msvc2010 outputs error, IDK why? maybe a bug).... I also tested it in Qt4.8.4 (msvc2008) and it works. Never tried on mingw and msvc2010 though.
-
wrote on 13 Dec 2012, 13:37 last edited by
[quote author="Code_ReaQtor" date="1355405419"]mingw and msvc2010 outputs error, IDK why? maybe a bug).... .[/quote]
What error do you have ? On my end it works perfectly with mingw up to 4.7.4 and with VC2010
-
wrote on 13 Dec 2012, 14:34 last edited by
[quote author="cincirin" date="1355405869"]
What error do you have ? On my end it works perfectly with mingw up to 4.7.4 and with VC2010
[/quote]I actually got the error on Qt 4.8.3 ONLY (mingw and msvc2010)
It says something like "COFF: file invalid or corrupt"
At first, I thought the problem was with the .ico file that I used but I compiled it with another version and it worked.
To summarize:
It didn't worked on Qt4.8.3 mingw and msvc2010
It worked with Qt4.8.3 msvc2008 and other versions not mentioned above (Qt4.8.4 mingw and msvc2010 not tested) -
wrote on 13 Dec 2012, 14:53 last edited by
ok, I didn't tested with 4.8.3 :-), but with 4.8.4 it work with vc2010 (and maybe with mingw)
-
wrote on 6 Mar 2013, 10:56 last edited by
The COFF file error is triggered by a bug in the compiler. I documented how I managed to get the fix installed here: https://qt-project.org/wiki/Category:Tools::msvc