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

Drag/drop of "text/plain" does not work, QMimeData::text() returns an empty string

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1: Critical
    • Resolution: Done
    • Affects Version/s: 6.2.4
    • Fix Version/s: 6.2.5, 6.4.0 Beta1
    • Component/s: GUI: Drag and Drop
    • Labels:
      None
    • Environment:
      Qt 6.2.4, openSUSE Leap 15.3, gcc 11.2.1
    • Platform/s:
      Linux/X11
    • Commits:
      46d047b76c (qt/qtbase/dev) 46d047b76c (qt/tqtc-qtbase/dev) bab62f68a4 (qt/tqtc-qtbase/6.2)

      Description

      Regression: Drag/drop of "text/plain" does not work, QMimeData::text() returns an empty string. This bug existed in Qt 5.15 and was fixed with QTBUG-84662. Citation from the commit message: "this is not needed for Qt 6 due to QTextCodec was replaced by QStringConverter".

      Suggested fix in qmimedata.cpp (line 156):

          if (data.metaType().id() == QMetaType::QByteArray) {
              // see if we can convert to the requested type
              switch (typeId) {
              case QMetaType::QString: {
                  const QByteArray ba = data.toByteArray();
                  if (ba.isNull())         // <===============
                      return QVariant();   // <=============== not QString()
                  if (format == QLatin1String("text/html")) {
                      auto encoding = QStringConverter::encodingForHtml(ba);
                      if (encoding) {
                          QStringDecoder toUtf16(*encoding);
                          return QString(toUtf16(ba));
                      }
                      // fall back to utf8
                  }
                  return QString::fromUtf8(ba);
              }
      

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              liaqi Liang Qi
              Reporter:
              wschenke Winfried Schenke
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes