diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index 536318b3a8b..8d23d167b06 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -2442,14 +2442,14 @@ QDataStream &operator>>(QDataStream &s, QPainterPath &p) int size; s >> size; - if (size == 0) + if (size == 0) { + p = {}; return s; + } p.ensureData(); // in case if p.d_func() == 0 - if (p.d_func()->elements.size() == 1) { - Q_ASSERT(p.d_func()->elements.at(0).type == QPainterPath::MoveToElement); - p.d_func()->elements.clear(); - } + p.detach(); + p.d_func()->elements.clear(); for (int i=0; i>(QDataStream &s, QPainterPath &p) s >> fillRule; Q_ASSERT(fillRule == Qt::OddEvenFill || fillRule == Qt::WindingFill); p.d_func()->fillRule = Qt::FillRule(fillRule); - p.d_func()->dirtyBounds = true; - p.d_func()->dirtyControlBounds = true; - if (errorDetected) + if (errorDetected || p.d_func()->elements.isEmpty()) p = QPainterPath(); // Better than to return path with possibly corrupt datastructure, which would likely cause crash return s; } diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp index 89631a7f282..c00dc3a78a5 100644 --- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp +++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp @@ -765,6 +765,21 @@ void tst_QPainterPath::testOperatorDatastream() } QCOMPARE(other, path); + + // Check reset & detach + QPainterPath p3; + p3.lineTo(1, 1); + QCOMPARE(p3.elementCount(), 2); + QPainterPath p4 = p3; + QCOMPARE(p4.elementCount(), 2); + { + QFile data(tempDir.path() + "/data"); + QVERIFY(data.open(QFile::ReadOnly)); + QDataStream stream(&data); + stream >> p3; + } + QCOMPARE(p3.elementCount(), path.elementCount()); + QCOMPARE(p4.elementCount(), 2); } void tst_QPainterPath::closing()