3

Weird problem I'm struggling with. On the same folder as my "*.pro" QT project file I have a Resources/myIcon.png.

I am trying to set that as the Icon for my built application, running on OSX. I read the documentation and it suggests to put a "ICON = " in the .pro file. I did that, but for some reason, the icon IS copied over the the resources folder inside my app's content, but the .pfile's icon field remains empty. Even when I change it manually to "resources/myIcon.png" it will not work.

What am I doing wrong?

JasonGenX
  • 4,952
  • 27
  • 106
  • 198

3 Answers3

16

Manually delete the generated app bundle. Run QMake followed by Rebuild All is not sufficient!

Timmmm
  • 88,195
  • 71
  • 364
  • 509
  • 1
    Dude! That fixed me. I was racking my brains for hours on this and your little tip helped me. All I had to do was create a MyIcon.icns using [this post](http://stackoverflow.com/a/20703594/105539), dropped it in the project directory, added `ICON = MyIcon.icns` to the .pro file, and then followed your advice here. Works! – Volomike Aug 25 '15 at 15:20
  • Ha I just had this exact problem again and tried to upvote myself... Shame this still isn't fixed. – Timmmm May 16 '17 at 14:12
  • It has taken me all day to find this answer. I have some apps that will display the icon, some that will not. Deleting the app bundle followed by qmake and rebuild seems to get it working. Also, I can make it show the icon by renaming the app bundle. Even if I then rename it back to the original, it carries on working. I am wondering if the problem is with MACOS (10.12.6 here) caching the icon information and not noticing the change? Try changing the TARGET name, then rebuilding. That can bring the icon back. – Peter Harrison Sep 09 '18 at 00:14
3

Don't set the full pathname within the application bundle for the icon file in the Info.plist. Just set the filename. Mac OS knows to look in AppName.app/Contents/Resources for it.

And yes, it must be an ICNS file as far as I'm aware. You can use the 'Icon Composer' utility that is part of the Mac OS development tools to create an .icns from a .png.

Grant Limberg
  • 20,913
  • 11
  • 63
  • 84
1

Are you referring to the icon which appears in the dock? I added a .ico to my application's resource file, then set it as my icon with the following call

QApplication::qApp()->setWindowIcon(QIcon(<resource path>));
ZestyMeta
  • 121
  • 3
  • Two interesting points. Firstly, setting the icon using this->setWindowIcon in the main application window does not unfortunately set the dock icon, although it sets the window icon. Secondly, QApplication::setWindowIcon is fine (no 'qApp()->' is needed), and sets both the dock icon and the application window icon, although the dock icon is set after the bouncing phase, so the default icon appears for a short time; which is perfectly acceptable for most purposes. – Graham Asher Nov 25 '15 at 12:08