简体   繁体   English

在Qt Creator中设置OSX的应用程序图标

[英]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. 遵循此处针对OSX的指示: http : ICON = myapp.icns ,说明我要做的就是将ICON = myapp.icns添加到我的项目文件中。 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 我使用了从Qt本身偷走的ICNS文件之一(换句话说,它应该可以工作,这不是转换问题),并且在运行qmake之后进行构建时出现错误

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). 我经常使用make,但是对Qt的经验很少,所以我不知道它在试图告诉我什么(我什至不知道这些文件路径来自何处)。 The .icns file has been added to the resources .qrc and is in the base directory of the project. .icns文件已添加到资源.qrc中,并且位于项目的基本目录中。

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 : 这是Simon Warta要求的grep命令的输出:

_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: 从myapp.pro:

ICON = myapp.icns
QMAKE_INFO_PLIST = myapp.plist

QMAKE_INFO_PLIST must be called Info.plist . QMAKE_INFO_PLIST必须称为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. 这是因为OS X系统将查找具有该确切文件名的文件。

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 更新Makefile部分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 在源代码中搜索QMAKE_INFO_PLIST其他位置:在存储库的根目录中调用git grep QMAKE_INFO_PLIST
  4. Post the content of your Info.plist 发布您的Info.plist的内容
  5. Post the content of your .pro file 发布您的.pro文件的内容

I had to add to Project.pro: 我必须添加到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: 并在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. Qt似乎没有设置项目以将.icns文件复制到捆绑包中(至少在Qt 5.9中使用),因此将其保存在.plist文件中是没有用的。 The last three lines in the .pro file copy it manually. .pro文件中的最后三行手动将其复制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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