Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QIcons from QFileIconProvider can't be written and read from a stream
Forum Updated to NodeBB v4.3 + New Features

QIcons from QFileIconProvider can't be written and read from a stream

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 362 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Guy GizmoG Offline
    Guy GizmoG Offline
    Guy Gizmo
    wrote on last edited by
    #1

    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   : 123141
    

    Note that once original is converted to a QByteArray, that QByteArray does not have a correct size. It is in fact not properly converting original to a QByteArray at all.

    However, this is not the case for fixed. For whatever reason, manually constructing a new QIcon with the same pixmaps does not have this issue. Other methods for constructing a QIcon do 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 QFileInfo constructor with the path of any file on disk.)

    Is this a bug with QFileIconProvider? Or is there something I'm missing about the QIcon it returns, and there's something I need to do to be able to convert it to and from a QByteArray?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      Yes, I think it seems to be a bug of the file icon engine in qpa plugin.

      1 Reply Last reply
      1
      • Guy GizmoG Offline
        Guy GizmoG Offline
        Guy Gizmo
        wrote on last edited by
        #3

        I've submitted a bug report. Fortunately I've already found a workaround for the issue.

        Christian EhrlicherC 1 Reply Last reply
        0
        • Guy GizmoG Guy Gizmo

          I've submitted a bug report. Fortunately I've already found a workaround for the issue.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          Guy GizmoG 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @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 GizmoG Offline
            Guy GizmoG Offline
            Guy Gizmo
            wrote on last edited by
            #5

            @Christian-Ehrlicher https://bugreports.qt.io/browse/QTBUG-84743

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved