Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-664

mimeData encoding issues

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 5.12.0
    • 5.6, 5.9
    • PySide

    Description

      I am trying to drag and drop mimeData in a QTreeView using an QAbstractItemModel (Python 3.6), and I've stumbled upon a few different issues.

      1. I originally wanted to add a Python object to my mimeData stream. But there is no QVariant in PySide2. I can see this being a problem, as I believe there is no good workaround here; you simply cannot "drop" a Python object using drag and drop without QVariant. Am I mistaken?
      2. So I instead wanted to create a dictionary which I wanted to stream (using the "application/json" format). Before adding it as a string to the stream, I need to convert the dictionary to string and UTF8 encode it. I did this with json.dumps(d, ensure_ascii=False).encode('utf-8'). But in the mimeDropData, there's no clear way to decode it. In C++ you would use QString::fromUtf8(). But there's no QString type in PySide2. Unicode is not a thing in Python 3 and str() doesn't work.
      3. QByteArray.data() seems broken; b = QByteArray("hi 猫") , b.data() returns b'hi \xe7' , but it should return b'hi \xe7\x8c\xab'

      Attachments

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

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            fredrikaverpil Fredrik Averpil
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes