QIcons from QFileIconProvider can't be written and read from a stream
-
Unless I'm missing something, the following code does not seem to work correctly:
#include <QDebug> #include <QApplication> #include <QIcon> #include <QFileIconProvider> #include <QByteArray> #include <QDataStream> #include <QFileInfo> static QByteArray QIconToQByteArray(const QIcon &icon) { QByteArray iconData; QDataStream iconDataStream(&iconData, QIODevice::WriteOnly); iconDataStream << icon; return iconData; } int main(int argc, char *argv[]) { QApplication a(argc, argv); QIcon original = QFileIconProvider().icon(QFileInfo("/System/Library/CoreServices/Finder.app")); QIcon fixed; foreach(const QSize &size, original.availableSizes()) { fixed.addPixmap(original.pixmap(size)); } qDebug() << "original :" << original; qDebug() << "original converted:" << QIconToQByteArray(original).size(); qDebug() << "fixed converted :" << QIconToQByteArray(fixed).size(); return 0; }When I run this on macOS, the output I get is:
original : QIcon(availableSizes[normal,Off]=(QSize(32, 32), QSize(64, 64), QSize(128, 128), QSize(256, 256), QSize(512, 512)),cacheKey=0x100000000) original converted: 42 fixed converted : 123141Note that once
originalis converted to aQByteArray, thatQByteArraydoes not have a correct size. It is in fact not properly convertingoriginalto aQByteArrayat all.However, this is not the case for
fixed. For whatever reason, manually constructing a newQIconwith the same pixmaps does not have this issue. Other methods for constructing aQIcondo not exhibit this problem either.I've reproduced this issue in both macOS and Windows, using both Qt 5.9.9 and Qt 5.15.0. (To run this code in Windows, simply replace the path passed into the
QFileInfoconstructor with the path of any file on disk.)Is this a bug with
QFileIconProvider? Or is there something I'm missing about theQIconit returns, and there's something I need to do to be able to convert it to and from a QByteArray? -
@Guy-Gizmo said in QIcons from QFileIconProvider can't be written and read from a stream:
I've submitted a bug report.
Please post the bug number here for reference.
-
@Guy-Gizmo said in QIcons from QFileIconProvider can't be written and read from a stream:
I've submitted a bug report.
Please post the bug number here for reference.