How to get the actual main window / application icon(s) regadless of how they have been set?

  • I'm testing on Windows, but I'm making a cross-platform app for Win / Linux / Mac.

    I need QApplication::windowIcon() to work. The problem is it works if I called "setWindowIcon" previously, but not if I've set an icon from a resource file. Is there any other, versatile way to get the icon? If not, how can I get the right icon from resource file, assuming I don't want to hardcode its resource name? I. e., how to determine and retrieve it at runtime dynamically so that the code remains working when icon resource name changes?

  • Lifetime Qt Champion


    Use an alias for the resource so even if you change the file name as long as keep the same alias you're good.

  • But what if I've set the icon by specifying .rc file on Windows or .icns on Mac, without even having a .qrc file? How to retrieve that icon at runtime, with all its sizes?

  • Lifetime Qt Champion

    If you want absolutely the same file then just embed it in the resource file

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.