From 40a6845bcce22aca96e1dee26360bdff3e9520fb Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 22 Oct 2014 16:47:01 +0200 Subject: Fix assignment to QObject pointer properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit ammends 59ed8c355b99df0b949003a438ab850274261aa0 to always query the Qt meta-type registry to retrieve the QMetaObject for a QObject pointer type. Change-Id: I70d876a5acfa23967fd1a57c96fcd5ac853eaf49 Task-number: QTBUG-39614 Reviewed-by: Jędrzej Nowacki Reviewed-by: Ulf Hermann --- tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/auto/qml/qqmlproperty') diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index 6cd1eafafd..62ccec5794 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -1157,6 +1157,17 @@ void tst_qqmlproperty::read() QVERIFY(v.canConvert(QMetaType::QObjectStar)); QVERIFY(qvariant_cast(v) == o.qObject()); } + { + QQmlEngine engine; + PropertyObject o; + QQmlProperty p(&o, "qObject", &engine); + QCOMPARE(p.propertyTypeCategory(), QQmlProperty::Object); + + QCOMPARE(p.propertyType(), qMetaTypeId()); + QVariant v = p.read(); + QVERIFY(v.canConvert(QMetaType::QObjectStar)); + QVERIFY(qvariant_cast(v) == o.qObject()); + } // Object property { @@ -1432,6 +1443,23 @@ void tst_qqmlproperty::write() QCOMPARE(newData.value(), newObject); QCOMPARE(newData.value(), newObject); } + { + QQmlEngine engine; + PropertyObject o; + QQmlProperty p(&o, QString("qObject"), &engine); + QCOMPARE(o.qObject(), (QObject*)0); + QObject *newObject = new MyQObject(this); + QCOMPARE(p.write(QVariant::fromValue(newObject)), true); + QCOMPARE(o.qObject(), newObject); + QVariant data = p.read(); + QCOMPARE(data.value(), newObject); + QCOMPARE(data.value(), newObject); + // Incompatible types can not be written. + QCOMPARE(p.write(QVariant::fromValue(new MyQmlObject(this))), false); + QVariant newData = p.read(); + QCOMPARE(newData.value(), newObject); + QCOMPARE(newData.value(), newObject); + } } void tst_qqmlproperty::reset() -- cgit v1.2.3