.ico图标未显示在Windows上

时间:2012-12-15 11:02:18

标签: qt plugins icons toolbar ico

我按照The Qt Resource System指南和 .ico图标出现在Linux上。

当我尝试从Qt Creator运行应用程序时,Windows上没有显示图标。

怀疑基于Qt/C++: Icons not showing up when program is run under windows O.S的插件问题,但我未能从指南How to Create Qt Plugins中弄清楚该怎么做。

是插件问题还是为什么Windows上没有显示图标?

如果是插件问题:如何告诉我的应用程序在哪里可以找到qico.dll?


环境详情:

适用于:Kubuntu 12.04 LTS,Qt Creator 2.4.1和Qt 4.7.4(64位)

失败:Windows XP SP2 32位,Qt Creator 2.4.1和Qt 4.7.4(32位)

Everyting是默认的(开箱即用),我没有弄乱设置。

resources.qrc

<!DOCTYPE RCC><RCC version="1.0">
    <qresource>
        <file>images/spreadsheet.ico</file>
    </qresource>
</RCC>

还尝试使用<qresource prefix="/">

来自 applicaton.pro

RESOURCES += \
    resources.qrc

OTHER_FILES += \
    images/spreadsheet.ico

在相应的源文件

QIcon(":/images/spreadsheet.ico")

我也尝试过Deploying an Application on Windows

QDir plugins(QCoreApplication::applicationDirPath()+"/plugins");

qDebug() << "Plugin directory" << plugins.absolutePath() << "found?" << plugins.exists();

app.addLibraryPath(plugins.absolutePath());

使用插件目录中的qico.dll。它应用程序打印出plugins目录,但图标仍未显示。

我再说一遍:适用于Linux。

2 个答案:

答案 0 :(得分:15)

对于未来的Google访问者:您可能会根据问题阅读评论,因为这就是这个答案诞生的地方。

所以问题是默认情况下ico不支持QIcon格式,你需要一个插件。在这种情况下,列出QIcon支持的格式的QImageReader::supportedImageFormats()函数可能会有所帮助。

如果您的格式不受支持,您可以尝试将imageformats文件夹从Qt的plugins目录复制到您的可执行文件所在的目录中。如果您的应用位于c:\myapp文件夹中,则应该有c:\myapp\imageformats文件夹(不是c:\myapp\plugins\imageformats)。否则,您必须使用QCoreApplication::addLibraryPath设置路径。

还要确保qico4.dllqicod4.dll(如果您在调试模式下构建)。

答案 1 :(得分:0)

只是详细说明QCoreApplication::addLibraryPath - 事物:

您需要提供&#34; 插件&#34; - 文件夹。不是子文件夹!

以下是 Python / PySide 用户使用PySide包位置的方法。您也可以在QtGui.QApplication使用app实例,如果您已经有pyside_plugin_path = os.path.join(sys.modules['PySide'].__path__[0], 'plugins') app.addLibraryPath(pyside_plugin_path) 实例:

doc

感谢#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include<wait.h> int main(void) { pid_t pid; char buf[1024]; char cp[50]; char ex[100]="exit"; int readpipe[2]; int writepipe[2]; long int a; int b; a=pipe(readpipe); b=pipe(writepipe); int test=1; int length; if (a == -1) { perror("pipe"); exit(EXIT_FAILURE); } if (b == -1) { perror("pipe"); exit(EXIT_FAILURE); } fflush(stdin); pid=fork(); if(pid==-1) { printf("pid:main"); exit(1); } while(test==1) { if(pid==0) { close(readpipe[1]); close(writepipe[0]); if(read(readpipe[0],buf,sizeof(buf)) < 0) { exit(1); } printf("\nSEND TO USER 1:"); fflush(stdin); fgets(cp, 50, stdin); length = strlen(cp); if(cp[length-1] == '\n') { --length; cp[length] = '\0'; } if(strcmp(cp,ex)==0) { test=0; break; } if(write(writepipe[1],cp,strlen(cp)+1) < 0) { exit(1); } } else { close(readpipe[0]); close(writepipe[1]); printf("\nSEND TO USER 2:"); fflush(stdin); fgets(cp, 50, stdin); length = strlen(cp); if(cp[length-1] == '\n') { --length; cp[length] = '\0'; } if(strcmp(cp,ex)==0) { test=0; break; } if(write(readpipe[1],cp,strlen(cp)+1) < 0) { exit(1); } if(read(writepipe[0],buf,sizeof(buf)) < 0) { exit(1); } } } close(readpipe[1]); close(writepipe[0]); close(readpipe[0]); close(writepipe[1]); return 0; }