Qt Snippet: Set window icon in Linux and Mac

In case of use Qt for Windows development the problem of the icon showed as window system icon is automatically resolved by add the .ico file as Windows resource. Windows already allow such feature and no need of additional efforts. In case of same code ported and compiled under Linux or Mac this step is not automatic.


However, basically, what you need is to simply manually assign by code your icon to the window. If you are moving from Windows application project add your .ico file to the Qt resource file (.qrc) of your project and, once done, add this line in window initialization phase:

QApplication::setWindowIcon(QIcon(":/my_prefix_if_any/my_window_icon.ico"));

Comments

Popular posts from this blog

Access GPIO from Linux user space

Android: adb push and read-only file system error

Tree in SQL database: The Nested Set Model