Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. How to convert QVector<QPainterPath> to QByteArray and convert it back?
Forum Updated to NodeBB v4.3 + New Features

How to convert QVector<QPainterPath> to QByteArray and convert it back?

Scheduled Pinned Locked Moved Solved Qt 6
2 Posts 2 Posters 540 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.
  • C Offline
    C Offline
    Christina123
    wrote on last edited by
    #1

    Hi, I am writing a code that can safely serialise a QVector<QPainterPath> to QByteArray and deserialise. I am not sure how to do so but I write some code based on my knowledge on it. Also, I am wondering what is the difference between sending data in terms of QByteArray or QDatastream. Any help is very welcome :)

    /*Serialising the data*/
    QByteArray Sender::convertPathToByteArray()
    {
        QByteArray data = QByteArray::fromRawData(reinterpret_cast<const char*>(path.constData()),sizeof(QPainterPath)*path.size());
        return data;
    }
    
    eyllanescE 1 Reply Last reply
    0
    • C Christina123

      Hi, I am writing a code that can safely serialise a QVector<QPainterPath> to QByteArray and deserialise. I am not sure how to do so but I write some code based on my knowledge on it. Also, I am wondering what is the difference between sending data in terms of QByteArray or QDatastream. Any help is very welcome :)

      /*Serialising the data*/
      QByteArray Sender::convertPathToByteArray()
      {
          QByteArray data = QByteArray::fromRawData(reinterpret_cast<const char*>(path.constData()),sizeof(QPainterPath)*path.size());
          return data;
      }
      
      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @Christina123 Use QDataStream:

      // QPainterPath to QByteArray
      QByteArray ba;
      QDataStream ds(&ba, QIODevice::WriteOnly);
      ds.setVersion(QDataStream::Qt_5_15);
      ds << path;
      qDebug() << ba;
      
      // QByteArray to QPainterPath
      QPainterPath path;
      QDataStream ds(ba);
      ds.setVersion(QDataStream::Qt_5_15);
      ds >> path;
      qDebug() << path;
      

      And knowing that QDataStream supports QVector then in your case the code doesn't change much:

      // QVector<QPainterPath> to QByteArray
      QByteArray ba;
      QDataStream ds(&ba, QIODevice::WriteOnly);
      ds.setVersion(QDataStream::Qt_5_15);
      ds << paths;
      qDebug() << ba;
      
      // QByteArray to QVector<QPainterPath>
      QVector<QPainterPath> paths;
      QDataStream ds(ba);
      ds.setVersion(QDataStream::Qt_5_15);
      ds >> paths;
      qDebug() << paths;
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      6

      • Login

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