简体   繁体   中英

Issue when loading an ico from a Qt resource file

I am using Qt Designer 4.8.4 and I include two files in the QMainWindow resource file: a .ico file and a .gif file. When loading from code using:

QPixmap p;
p.load(":/MyApp/media/logo.gif");  // does work
p.load(":/MyApp/media/logo.ico");  // does not work

The gif file works, but not the ico file. Is there any reason? I am using the ico file as the window icon and it is not showing when running the application.

And, YES, I am successfully compiling the qrc file since the GIF file is working .

Cheers,

*.ico is not supported.

By default, Qt supports the following formats:

Format Description Qt's support

BMP Windows Bitmap Read/write

GIF Graphic Interchange Format (optional) Read

JPG Joint Photographic Experts Group Read/write

JPEG Joint Photographic Experts Group Read/write

PNG Portable Network Graphics Read/write

PBM Portable Bitmap Read

PGM Portable Graymap Read

PPM Portable Pixmap Read/write

TIFF Tagged Image File Format Read/write

XBM X11 Bitmap Read/write

XPM X11 Pixmap Read/write

因为QPixmap只能简单地读取.ico文件,如果你想了解更多关于支持的格式,请看文档QPixmap

您可以将其格式转换为Qt支持的格式。

Guessing from your followup on the already chosen answer, you may want to have that ICO as the appwindow icon. That is possible, and also is perhaps why Qt Designer is capable of displaying it (trying to guess your intent). However, having it so doesn't involve any QPixmap coding, it's purely configuration affair. Described here (and yes, #worksforme) :

http://doc.qt.digia.com/qt/appicon.html

The accepted answer here is incorrect, or as mentioned in the comments, at least misleading. Qt has come with a plugin for handling ICO format since sometime in version 4.4. Here's a similar question from the same era.

For deployment, one needs to copy the plugins/imageformats/[lib]qico.[dll|so] file from the Qt installation used for building with to within their executable's directory. Put it in a subfolder, like so: <your_executable>/imageformats/qico.dll . If testing a debug build, the d suffix version of the lib is needed instead ( qicod.dll ).

( This newer question has been marked as a duplicate of this, so now 2 questions point to the wrong answer. Which is why I'm essentially repeating my post here.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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