Qt/C++: Icons not showing up when program is run

Joseph picture Joseph · Nov 6, 2010 · Viewed 31.9k times · Source

I've added a QAction to my QToolBar in my MainWindow in Qt Designer (using the Qt Creator IDE) and given that Action an icon (done by "Choose File" and selecting my .png located in the same directory as my project and source code). The icon shows up fine in the toolbar in Qt Designer, but does not show when the project is running. I've had similar trouble when choosing the title bar icon on windows. I've never used graphics in Qt before, is there something special I need to do?

Screenshot:

Answer

A. Vieira picture A. Vieira · Apr 2, 2016

I found myself doing all the right stuff, adding a qrc file and placing my icons there. When I run the program no deal. Turn out I was forgetting to run qmake:

  • Right click your project's name and select "Run qmake". Or go to Build>Run qmake.

Everytime you change something in the .pro file you need to run qmake again. Creating a resource file implicitly adds argunments to the .pro file, so you need to do it.

Hope it helps other people out there.