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. If you already have pickle (get/set state) and deepcopy methods, how do you convert to QByteArray?
Forum Update on Monday, May 27th 2025

If you already have pickle (get/set state) and deepcopy methods, how do you convert to QByteArray?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 1 Posters 311 Views
  • 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.
  • enjoysmathE Offline
    enjoysmathE Offline
    enjoysmath
    wrote on last edited by enjoysmath
    #1

    This is regarding useage of PyQt5. Not C++

    I'm implementing drag and drop for my Watermelon tool. It will suport DnD for almost all widgets appearing in the app.

    Easy enough though since each of my widget classes has been pickled / unpickled and deepcopied successfully. Thus, is there an easy way to convert the pickle data into QByteArray for the purpose of sticking in QMimeData?

    Thanks.

    https://github.com/enjoysmath
    https://math.stackexchange.com/users/26327/exercisingmathematician

    1 Reply Last reply
    0
    • enjoysmathE Offline
      enjoysmathE Offline
      enjoysmath
      wrote on last edited by
      #2

      I think you do:

      import _pickle as pickle

      obj = MyWidget()

      data = pickle.dumps(obj)
      byte_arr = QByteArray()
      data_stream = QDataStream(byte_array, QIODevice.WriteOnly)
      data_stream << data

      Also try passing in data directly to QByteArray() ctor.

      https://github.com/enjoysmath
      https://math.stackexchange.com/users/26327/exercisingmathematician

      1 Reply Last reply
      0
      • enjoysmathE Offline
        enjoysmathE Offline
        enjoysmath
        wrote on last edited by
        #3

        It's as easy as this:

        One one end:

                            item_data = QByteArray(dill.dumps(child))
                            mime_data = QMimeData()
                            mime_data.setData(self.mime_type, item_data)
        

        On the other end:

                   data = event.mimeData().data(self.mime_type).data()
                   drop = dill.loads(data)
        

        https://github.com/enjoysmath
        https://math.stackexchange.com/users/26327/exercisingmathematician

        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