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>bb10
parent
443ef0010a
commit
8310d636be
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue