简体   繁体   中英

Setting the application icon for OSX in Qt Creator

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

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 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM