summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoni Poikelin <joni.poikelin@qt.io>2019-10-14 12:31:40 +0300
committerJoni Poikelin <joni.poikelin@qt.io>2019-12-03 13:28:22 +0200
commit8310d636be068bb814418e2e6044c6dbd7df253a (patch)
treede1aa86d9046bef71829d088fca17f5c42bb201c
parent443ef0010ae68ac5a883fb9ab7677d9de719e70e (diff)
Fix serializing QUuid with QDataStream with Qt 4 stream versions
Fixes: QTBUG-76103 Change-Id: Iac92c33539940f5f67d014db5240c6dc14bfb772 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/corelib/kernel/qvariant.cpp4
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp20
-rw-r--r--tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp21
3 files changed, 43 insertions, 2 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 43a3fb1db0..84ad555f34 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -2577,8 +2577,8 @@ void QVariant::save(QDataStream &s) const
} else if (typeId >= QMetaType::QKeySequence && typeId <= QMetaType::QQuaternion) {
// and as a result these types received lower ids too
typeId +=1;
- } else if (typeId == QMetaType::QPolygonF) {
- // This existed in Qt 4 only as a custom type
+ } else if (typeId == QMetaType::QPolygonF || typeId == QMetaType::QUuid) {
+ // These existed in Qt 4 only as a custom type
typeId = 127;
fakeUserType = true;
}
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index 074cb07092..9e0881f1a6 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -278,6 +278,7 @@ private slots:
void accessSequentialContainerKey();
void fromStdVariant();
+ void qt4UuidDataStream();
private:
void dataStream_data(QDataStream::Version version);
@@ -5025,5 +5026,24 @@ void tst_QVariant::fromStdVariant()
#endif
}
+void tst_QVariant::qt4UuidDataStream()
+{
+ qRegisterMetaTypeStreamOperators<QUuid>();
+
+ QByteArray data;
+ QDataStream stream(&data, QIODevice::WriteOnly);
+ stream.setVersion(QDataStream::Qt_4_8);
+ QUuid source(0x12345678,0x1234,0x1234,0x12,0x23,0x34,0x45,0x56,0x67,0x78,0x89);
+ stream << QVariant::fromValue(source);
+ const QByteArray qt4Data = QByteArray::fromHex("0000007f000000000651557569640012345678123412341223344556677889");
+ QCOMPARE(data, qt4Data);
+
+ QDataStream input(&data, QIODevice::ReadOnly);
+ input.setVersion(QDataStream::Qt_4_8);
+ QVariant result;
+ input >> result;
+ QCOMPARE(result.value<QUuid>(), source);
+}
+
QTEST_MAIN(tst_QVariant)
#include "tst_qvariant.moc"
diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
index a057ec2207..0b9fc3c9ae 100644
--- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
+++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
@@ -113,6 +113,7 @@ private slots:
void guiVariantAtExit();
void iconEquality();
+ void qt4QPolygonFDataStream();
};
void tst_QGuiVariant::constructor_invalid_data()
@@ -783,5 +784,25 @@ void tst_QGuiVariant::iconEquality()
QVERIFY(a != b);
}
+void tst_QGuiVariant::qt4QPolygonFDataStream()
+{
+ qRegisterMetaTypeStreamOperators<QPolygonF>();
+
+ QByteArray data;
+ QDataStream stream(&data, QIODevice::WriteOnly);
+ stream.setVersion(QDataStream::Qt_4_8);
+ QPolygonF polygon;
+ polygon.append(QPointF(2, 3));
+ stream << QVariant::fromValue(polygon);
+ const QByteArray qt4Data = QByteArray::fromHex("0000007f000000000a51506f6c79676f6e46000000000140000000000000004008000000000000");
+ QCOMPARE(data, qt4Data);
+
+ QDataStream input(&data, QIODevice::ReadOnly);
+ input.setVersion(QDataStream::Qt_4_8);
+ QVariant result;
+ input >> result;
+ QCOMPARE(result.value<QPolygonF>(), polygon);
+}
+
QTEST_MAIN(tst_QGuiVariant)
#include "tst_qguivariant.moc"