1

Followed the directions here for OSX: http://doc.qt.io/qt-5/appicon.html stating that all I need to do is add ICON = myapp.icns to my project file. I used one of the ICNS files I stole from Qt itself (in other words, it should work, its not a conversion problem) and when build after running qmake I get the error

make: *** No rule to make target '1.22/MyProject.icns', needed by 'myapp.app/Contents/Resources/MyProject.icns'

I regularly use make but have little experience with Qt so I have no idea what it's trying to tell me here (I don't even know where these file paths are coming from). The .icns file has been added to the resources .qrc and is in the base directory of the project.

Any help is much appreciated. Thanks!

EDIT: Ok, the space in the file path was preventing the build. It now compiles and runs but still does not have a dock icon.

Here is the output of the grep command, as requested by Simon Warta:

_Qt_5_1_1_clang_64bit-Debug/Makefile | grep -C 3 icns
443
444 :
445     @$(DEL_FILE)
446     @sed -e "s,@SHORT_VERSION@,1.22,g" -e "s,@TYPEINFO@,????,g" -e "s,@ICON@,myapp.icns,g" -e "s,@EXECUTABLE@,myapp,g" -e "s,@TYPEINFO@,????,g" ../myapp1.22/myapp.plist >
447 myapp.app/Contents/Resources/myapp.icns: ../myapp1.22/myapp.icns
448     @test -d myapp.app/Contents/Resources/ || mkdir -p myapp.app/Contents/Resources/
--
448     @test -d myapp.app/Contents/Resources/ || mkdir -p myapp.app/Contents/Resources/
449     @$(DEL_FILE) myapp.app/Contents/Resources/myapp.icns
450     @$(COPY_FILE) ../myapp1.22/myapp.icns myapp.app/Contents/Resources/myapp.icns
451 dist:
452     @test -d .tmp/myapp1.22 || mkdir -p .tmp/myapp1.22

[[All my source files]]

477 compiler_rcc_clean:
478     -$(DEL_FILE) qrc_myapp.cpp
479 qrc_myapp.cpp: ../myapp1.22/myapp.qrc \
480         ../myapp1.22/myapp.icns \
481         ../myapp1.22/images/splashmyapp2.png \
482         ../myapp1.22/images/splashmyapp1.png \
483         ../myapp1.22/images/About.png \
--
--
481         ../myapp1.22/images/splashmyapp2.png \
482         ../myapp1.22/images/splashmyapp1.png \
483         ../myapp1.22/images/About.png
486     /Users/EngMac/Qt5.1.1/5.1.1/clang_64/bin/rcc -name myapp ../myapp1.22/myapp.qrc -o qrc_myapp.cpp

From myapp.pro:

ICON = myapp.icns
QMAKE_INFO_PLIST = myapp.plist
Community
  • 1
  • 1
pdel
  • 685
  • 12
  • 23
  • Is "1.22/" part of your source directory path? Do you have a space in there? Can you post the output of `cat -n your-build-dir/Makefile | grep icns` – Simon Warta Mar 26 '15 at 22:30
  • Try ICON = $$PWD/myapp.icns instead? qmake is a bit fussy about paths in 5.x from my experience. – Hamish Moffatt Mar 26 '15 at 23:51
  • 1
    `ICON = MyProject.icns` works fine in our Qt 5 project on OS X 10.9 and 10.10. – Simon Warta Mar 27 '15 at 10:14
  • Better use the following command to inspect your Makefile. That will give you all the context you need to understand what `make` is trying to do: `cat -n your-build-dir/Makefile | grep -C 3 icns` – Simon Warta Mar 27 '15 at 10:57
  • Yea, there might be a space in the directory path. I'll take a look monday and report back. Thanks for the input! – pdel Mar 27 '15 at 20:03
  • @pdel Are you using Qt 5.4? This question might be related but doesn't have to be: http://stackoverflow.com/questions/29329641/qt-5-4-cannot-set-app-icon-on-osx – Simon Warta Mar 29 '15 at 13:48
  • I'm on 5.1.1 but I seem to be having the same issue. There's no .plist file being generated... Also, yea, there was a space which I removed. It now compiles but I don't see any icon in the dock. – pdel Mar 30 '15 at 13:37
  • @pdel Can you add the output the grep commend above? Otherwise no one knows what really caused the error. Please add a link to my name in the comment, because otherwise I will not get notified. – Simon Warta Mar 30 '15 at 13:49
  • @Simon Warta here you go, sorry I didn't notice that before – pdel Mar 30 '15 at 15:44
  • Two things are sttrange: (1) you mix up `MyProject.icns` and `myapp.icns`. Is this a matter of example code or do you have some old files in your build directory? Them remove your build directory. (2) What is **nk**myapp.app/ in line 447? – Simon Warta Mar 30 '15 at 15:52
  • And (3): there is output missing. E.g. Line 446 must have a file output after `>` at the end. Did you have trouble copying the output? – Simon Warta Mar 30 '15 at 15:56
  • At one point I changed the names. I just went back through to check everything and updated the output. The `>` is actually how its displayed in the terminal. There doesn't appear to be anything there. – pdel Mar 30 '15 at 16:06
  • The file path of your `Info.plist` is missing at different points: (1) before `:` in 444, (2) after `(DEL_FILE)` in 445 and (3) after `>` in 446. Did you set `QMAKE_INFO_PLIST` manually in your project file? Looks like you set it to an empty string. – Simon Warta Mar 30 '15 at 16:10
  • added the relevant lines from the .pro file – pdel Mar 30 '15 at 16:14

3 Answers3

4

QMAKE_INFO_PLIST must be called Info.plist. It might be placed in a custom sub-directory of your choice but the filename is fixed. That is because the OS X system will look for a file with that exact filename.

Further debugging tips (orderd by importance):

  1. Post a current error message
  2. Update the Makefile parts cat -n [...]_Qt_5_1_1_clang_64bit-Debug/Makefile | grep -C 4 icns
  3. Search your source code for other places of QMAKE_INFO_PLIST: Call git grep QMAKE_INFO_PLIST in the root of your repository
  4. Post the content of your Info.plist
  5. Post the content of your .pro file
Simon Warta
  • 10,850
  • 5
  • 40
  • 78
  • I changed the to `QMAKE_INFO_PLIST = Info.plist` but its still not generating anything in the output directory. Any thoughts? – pdel Mar 30 '15 at 16:47
  • Did you entirely remove the build directory first? – Simon Warta Mar 30 '15 at 16:59
  • Yea, just rebuilt everything (as debug) after removing the build-debug directory but I'm still not getting anything – pdel Mar 30 '15 at 17:06
  • Okay then … Can you add the entire content of your `.pro` file as well as your `Info.plist`? – Simon Warta Mar 30 '15 at 17:12
  • I don't actually have an Info.plist, its not generating. Should I just manually create one? – pdel Mar 30 '15 at 17:21
  • No, you either have a custom `Info.plist` present because you need some special entry or you remove the line `QMAKE_INFO_PLIST = ...`. By default you don't need it. – Simon Warta Mar 30 '15 at 17:25
  • Huh... well it works perfectly now. I'm getting the icon and everything. Thanks a ton for all the help. Sorry to take up most of your monday morning... – pdel Mar 30 '15 at 17:30
  • Your're welcome. Where did you get the idea that a `.pro` file need a `QMAKE_INFO_PLIST`? Hope that is not in some strange tutorial – Simon Warta Mar 30 '15 at 17:39
  • I think it just snuck in while messing with it. I'm not at all familiar with the qt ecosystem and the documentation on plist files for qt is pretty sparse. I just saw the line and went with it assuming it was output instead of input. – pdel Mar 30 '15 at 18:08
  • @pdel Right, epecially the documentation of `qmake` is pain in the ass – Simon Warta Mar 30 '15 at 18:12
2

I had to add to Project.pro:

ICON = Project.icns
QMAKE_INFO_PLIST = Info.plist

# Qt doesn't copy over the .icns file ?!
RESOURCE_FILES.files = $$ICON
RESOURCE_FILES.path = Contents/Resources
QMAKE_BUNDLE_DATA += RESOURCE_FILES

and in Info.plist:

<key>CFBundleIconFile</key>
<string>ContentCanvas</string>

It seems that Qt doesn't set the project up to copy the .icns file into the bundle (at least with Qt 5.9), so having it in the .plist file is useless. The last three lines in the .pro file copy it manually.

prewett
  • 1,587
  • 14
  • 19
0

QApplication app(argc, argv);

app.setWindowIcon(QIcon(":/icons/test_icon.icns")); // Your path icon