Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
801 views
in Technique[技术] by (71.8m points)

qt - .ico icons not showing up on Windows

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:myappimageformats folder (not c:myapppluginsimageformats). 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...