Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-96215

QMimeData not serialized correctly in Qt 6

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 6.0.4, 6.1.3, 6.2.0 Beta3
    • Core: I/O
    • Linux/X11

    Description

      QMimeData objects cannot be properly serialized.

      This is a regression in Qt 6.

       

      The following code can be used for reproducing the issue:

      QMimeData mimeData;
      mimeData.setText("Hello World");
      mimeData.setHtml("<strong>Hello World</strong>");
      
      QMimeData mimeData2;
      
      {
          QByteArray byteArray;
          {
              QDataStream stream(&byteArray, QIODevice::WriteOnly);
              stream << mimeData;
          }
          {
              QDataStream stream(&byteArray, QIODevice::ReadOnly);
              stream >> mimeData2;
          }
      }
      
      qWarning() << mimeData.formats();
      qWarning() << mimeData.data("text/plain");
      qWarning() << mimeData2.formats();
      qWarning() << mimeData2.data("text/plain");
      

       

      Output that is produced in different Qt versions:

      Qt 5.12.11 (but formats order varies)

      ("text/plain", "text/html")
      "Hello World"
      ("text/html", "text/plain")
      "Hello World"
      

      Qt 5.15.2

      ("text/plain", "text/html")
      "Hello World"
      ("text/plain", "text/html")
      "Hello World"
      

      Qt 6.0.4 , Qt 6.1.3 , Qt 6.2.0 Beta3 (format loss, wrong text returned)

      QList("text/plain", "text/html")
      "Hello World"
      QList("text/plain")
      "text/plain"
      

       

      I originally encountered the issue when using QClipboard, but it turned out to be irrelevant for the case.

      For exercising the issue further, though, one could tweak the snippet above to source the QMimeData object from the QClipboard instance like this:

      const QMimeData& mimeData{*QApplication::clipboard()->mimeData()};

       

      The output in this case is:

      Qt 5.12.11 (but formats order varies)

      ("TIMESTAMP", "TARGETS", "SAVE_TARGETS", "MULTIPLE", "text/plain", "chromium/x-web-custom-data", "text/html")
      "for (int i = 0; i < 10; ++i)"
      ("TIMESTAMP", "TARGETS", "SAVE_TARGETS", "MULTIPLE", "chromium/x-web-custom-data", "text/html", "text/plain")
      "for (int i = 0; i < 10; ++i)"
      

      Qt 5.15.2

      ("TIMESTAMP", "TARGETS", "SAVE_TARGETS", "MULTIPLE", "text/plain", "chromium/x-web-custom-data", "text/html")
      "for (int i = 0; i < 10; ++i)"
      ("TIMESTAMP", "TARGETS", "SAVE_TARGETS", "MULTIPLE", "text/plain", "chromium/x-web-custom-data", "text/html")
      "for (int i = 0; i < 10; ++i)"
      

      Qt 6.0.4 , Qt 6.1.3 , Qt 6.2.0 Beta3 (format loss, wrong text returned)

      QList("TIMESTAMP", "TARGETS", "SAVE_TARGETS", "MULTIPLE", "text/plain", "chromium/x-web-custom-data", "text/html")
      "for (int i = 0; i < 10; ++i)"
      QList("text/plain")
      "TIMESTAMP"
      

       

      In this test, "for (int i = 0; i < 10; ++i)" had been copied from my IDE into the clipboard; the IDE provides a few extra MIME formats.

      Attachments

        Activity

          People

            thiago Thiago Macieira
            cristian64 Christian Aguilera
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: