.ico icons not showing up on Windows
Asked Answered
L

2

10

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.

Letitialetizia answered 15/12, 2012 at 11:2 Comment(14)
By 'not showing up' do you mean they don't appear in your application, or that they are not being generated on disk?Miocene
@IanAtkin They don't appear in my application.Letitialetizia
So, is it possible that they are being generated incorrectly? Windows can get a bit finicky over bit-depth, size in pixels, etc.Miocene
How do you set this icon in your application? On Windows icon should be packed in exe file. Also check if ico format is supported by QIcon or try convert to different format like png.Blen
@doc I checked the qrc_resources.cpp file generated by moc. I believe the icons are packed into the exe file: I see the correct paths in comments and large binary data in this generated source file. Converting the icons to a different format is a workaround which might work and is my fallback option but I would like to get an answer to my question.Letitialetizia
@IanAtkin Please tell me what to do. I am afraid I don't understand your question.Letitialetizia
@Letitialetizia this is crucial. Because if QIcon does not support ico format, then you have an answer. You should list supported formats using QImageReader::supportedImageFormats () function and see if ico is there on your Windows machine.Blen
If it's not there you may copy imageformats directory from Qt's plugin directory into your application folder (where executable is). It should work then.Blen
@doc OK, I will try. But it would be VERY VERY strange if the Microsoft's .ico format is supported on Linux but not on Windows.Letitialetizia
@doc I tried imageformats as well, didn't work either.Letitialetizia
@Letitialetizia First try to list formats. Are you sure that you have plugins in the correct path? imageformats should be in application folder (so if your app is in c:\myapp you should have c:\myapp\imageformats folder not c:\myapp\plugins\imageformats) and you don't have to set anything. Also make sure that qico4.dll and qicod4.dll (if you build in debug mode) are there.Blen
@doc The answer to your previous question: NO, ico is NOT supported: ("bmp", "pbm", "pgm", "png", "ppm", "xbm", "xpm"). I will check again the imageformats stuff and get back to you.Letitialetizia
@doc OK, the problem was that I put qico4.dll there and not qicod4.dll so it wasn't loaded in debug mode.Letitialetizia
@doc Please write up this discussion for future google visitors, I would like to accept it as the answer.Letitialetizia
B
19

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.

Blen answered 15/12, 2012 at 15:4 Comment(0)
A
0

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!

Adobe answered 10/11, 2016 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.