How to set application icon in a Qt-based project?


Question

How do you set application icon for application made using Qt? Is there some easy way? It's a qmake-based project.

1
51
10/16/2013 1:24:01 PM

Accepted Answer

For Qt 5, this process is automated by qmake. Just add the following to the project file:

win32:RC_ICONS += your_icon.ico

The automated resource file generation also uses the values of the following qmake variables: VERSION, QMAKE_TARGET_COMPANY, QMAKE_TARGET_DESCRIPTION, QMAKE_TARGET_COPYRIGHT, QMAKE_TARGET_PRODUCT, RC_LANG, RC_CODEPAGE.

For Qt 4, you need to do it manually. On Windows, you need to create a .rc file and add it to your project (.pro). The RC file should look like this:

IDI_ICON1 ICON DISCARDABLE "path_to_you_icon.ico"

The .pro entry should also be win32 specific, e.g.:

win32:RC_FILE += MyApplication.rc
86
11/20/2014 6:13:30 PM

To extend Rob's answer, you can set an application icon for macOS by adding and modifying the following line onto your .pro file.

macx: ICON = <app_icon>.icns

Note that the ICON qmake variable is only meant to target macOS.

For Windows, use

  • RC_ICONS = <app_icon>.ico if you're attaching a .ico file
  • or RC_FILE = <app_icon>.rc if you want to attach your icon through a .rc file. (Be sure to add IDI_ICON1 ICON DISCARDABLE "myappico.ico" into the rc file. Indentation not mine.)

For further reading, see Setting the Application Icon.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon