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. how to serialize QMimeData
Qt 6.11 is out! See what's new in the release blog

how to serialize QMimeData

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 663 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.
  • C Offline
    C Offline
    Cyrille de Brebisson
    wrote on last edited by
    #1

    Hello,

    I need to save and load a QMimeData object.

    What is the easiest way to do this?

    Thanks,
    Cyrille

    jsulmJ 1 Reply Last reply
    0
    • C Cyrille de Brebisson

      Hello,

      I need to save and load a QMimeData object.

      What is the easiest way to do this?

      Thanks,
      Cyrille

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Cyrille-de-Brebisson I would say you need to implement << and >> operators for QMimeData (see http://doc.qt.io/qt-5/qdatastream.html)

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3
        QDataStream &operator<<(QDataStream &stream, const QMimeData &data)
        {
        const QStringList formats = data.formats();
        stream << (qint32)formats.size();
        for(const QString& format : formats)
        stream << format << data.data(format);
        return stream;
        }
        QDataStream &operator>>(QDataStream &stream, QMimeData &data)
        {
        data.clear();
        qint32 size;
        QString format;
        QByteArray formatData;
        stream >> size;
        while(size-->0){
        stream >> format >> formatData;
        data.setData(format,formatData);
        }
        return stream;
        }
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2

        • Login

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