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

Inconsistent QPolygonF serialization

XMLWordPrintable

    • 1ebee8980 (dev), 113ecff9f (6.7), de6b76229 (6.6)

      Qt user reported following:
      "
      I've been struggling trying to understand how is QPolygonF serialized. This is the snippet of my unit test

      void checkPoly()
      {
      QPolygonF poly;
      poly.append(QPointF(1,2));
      poly.append(QPointF(3,4));
      
      QByteArray qtBuf;
      {//save the polygon to a bytearray
      QBuffer b;
      QDataStream strm(&b);
      b.open(QIODevice::WriteOnly);
      strm << poly;
      qtBuf = b.buffer();
      }
      {//read the polygon from the bytearray
      QBuffer b;
      b.setData(qtBuf);
      QDataStream strm(&b);
      b.open(QIODevice::ReadOnly);
      strm >> poly;
      QCOMPARE(poly.size(), 2);
      }
      }
      

      This fails in Qt 5.15.16 because when loading the polygon again from the binary buffer the new values don't replace the old ones, they are appended to the existing ones and the final size is 4 instead of 2. That's an unexpected behavior or at least the function is not properly documented. Changing the code to use QPolygon or QVector<QPointF> or QList<QPointF> creates a container of size 2 as I would expect.
      "
      https://doc.qt.io/qt-5/qpolygon.html#operator-gt-gt

      Mentions that:
      "Reads a polygon from the given stream into the given polygon"

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

            thiago Thiago Macieira
            tero.pelkonen Tero Pelkonen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There is 1 open Gerrit change