.ico icons not showing up on Windows

Deadly 提交于 2019-12-17 20:35:06

问题


I followed the The Qt Resource System guide and the .ico icons appear on Linux.

The icons are not showing up on Windows when I try to run the applicaton from Qt Creator.

I suspect a plugin issue based on Qt/C++: Icons not showing up when program is run under windows O.S but I failed to figure out what to do from the guide How to Create Qt Plugins.

Is it a plugin issue or why aren't the icons showing up on Windows?

If it is a plugin issue: How do I tell my applicaton where to find the qico.dll?


Details of the environment:

Works on: Kubuntu 12.04 LTS, Qt Creator 2.4.1 and Qt 4.7.4 (64 bit)

Fails on: Windows XP SP2 32 bit, Qt Creator 2.4.1 and Qt 4.7.4 (32 bit)

Everyting is at its default (as installed out of the box), I did not mess with the settings.

resources.qrc

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

Also tried with <qresource prefix="/">.

From the applicaton.pro

RESOURCES += \
    resources.qrc

OTHER_FILES += \
    images/spreadsheet.ico

In the corresponding source file

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

I also tried as written in Deploying an Application on Windows

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

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

app.addLibraryPath(plugins.absolutePath());

with the qico.dll in the plugins directory. It application prints that the plugins directory exists but the icons still don't show up.

I repeat: it works on Linux.


回答1:


For future google visitors: you may read comments under the question, because this is where this answer was born.

So the problem is that ico format is not supported by QIcon by default and you need a plugin for this. In such cases QImageReader::supportedImageFormats() function, which lists formats supported by QIcon may be helpful.

In case your format is not supported, you may try to copy imageformats folder from Qt's plugins directory into directory where your executable resides. If your app lies in c:\myapp folder you should have c:\myapp\imageformats folder (not c:\myapp\plugins\imageformats). Otherwise you have to set paths using QCoreApplication::addLibraryPath.

Also make sure that qico4.dll and qicod4.dll (if you build in debug mode) are there.




回答2:


Just to elaborate on the QCoreApplication::addLibraryPath-thing:

You need to make the "plugins"-folder available. Not the subfolders!

Here is a way for Python/PySide users to use the PySide package location. You can also just use your QtGui.QApplication instance, which is app here, if you have one already:

pyside_plugin_path = os.path.join(sys.modules['PySide'].__path__[0], 'plugins')
app.addLibraryPath(pyside_plugin_path)

And thanks already to doc!



来源:https://stackoverflow.com/questions/13891591/ico-icons-not-showing-up-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!