Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

icons

qt

toolbar

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:

like image 747
Joseph Avatar asked Nov 06 '10 18:11

Joseph


People also ask

How do I add icons to my Qt app?

Setting the Application Icon on Windows This can be done using Microsoft Visual Studio: Select File >> New, and choose the Icon File. Note: You need not load the application into the Visual Studio IDE as you are using the icon editor only.

Can I use Qt with C++?

Qt supports various compilers, including the GCC C++ compiler, the Visual Studio suite, PHP via an extension for PHP5, and has extensive internationalization support. Qt also provides Qt Quick, that includes a declarative scripting language called QML that allows using JavaScript to provide the logic.


2 Answers

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.

like image 141
A. Vieira Avatar answered Sep 21 '22 05:09

A. Vieira


Did you make a QRC file (that is, Qt's equivalent of a resource file?) If not, that would explain what you're seeing. The icons will show up in the creator, but not in the final compiled executable. Have a look at this:

http://doc.qt.io/qt-5/resources.html

like image 37
Bart Avatar answered Sep 21 '22 05:09

Bart