From ce0c22d4da46664636e651285f6e3ba38e77aea7 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 29 Oct 2009 10:40:14 +0100 Subject: Fix qvariant_cast when a QVariant is really inside a QVariant This fix the QPropertyAnimation test. Reviewed-by: Gabriel Reviewed-by: Thierry --- src/corelib/kernel/qvariant.h | 3 +++ tests/auto/qvariant/tst_qvariant.cpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index a1ab4e9..3c10788 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -581,6 +581,9 @@ template inline T qvariant_cast(const QVariant &v) template<> inline QVariant qvariant_cast(const QVariant &v) { + static const int vid = qRegisterMetaType("QVariant"); + if (vid == v.userType()) + return *reinterpret_cast(v.constData()); return v; } diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp index 61e9a4f..e2a606f 100644 --- a/tests/auto/qvariant/tst_qvariant.cpp +++ b/tests/auto/qvariant/tst_qvariant.cpp @@ -3380,6 +3380,10 @@ void tst_QVariant::variantInVariant() QVariant var8 = qvariant_cast(QVariant::fromValue(QVariant::fromValue(str))); QCOMPARE((int)var8.type(), (int)QVariant::String); QCOMPARE(qvariant_cast(QVariant(qvariant_cast(var8))), str); + + QVariant var9(qMetaTypeId(), &var1); + QCOMPARE(var9.userType(), qMetaTypeId()); + QCOMPARE(qvariant_cast(var9), var1); } QTEST_MAIN(tst_QVariant) -- cgit v0.12