aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@theqtcompany.com>2014-12-01 14:37:09 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2014-12-13 01:36:30 +0100
commit450883d16b51b326e5d517de1517e14bf906df69 (patch)
tree748757eaf094e5b1289884730191658b95140fd3 /tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
parenta3d89b09b77c268f3c279f207c1df0aa1415dea9 (diff)
Read and write QObject pointer properties in QML without registration.
Previously, accessing QObject pointer properties from QML would require these types to be registered with qRegisterMetaType(), but this shouldn't be necessary if we're able to read/write the property, because the moc generates code that calls qRegisterMetaType in the static meta-call implementation. So when resolving a property in the property cache and we can't resolve, fall back to placing the static meta-call to register the type, similar to what QMetaType::userType() does. Change-Id: Ic8b00ed93a1e5e42cf7aaaf1c355e89557485c59 Reviewed-by: Christopher Adams <chris.adams@jollamobile.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp78
1 files changed, 77 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index c05ac7a052..e966052ce8 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -323,6 +323,8 @@ private slots:
void contextObjectOnLazyBindings();
void garbageCollectionDuringCreation();
void qtbug_39520();
+ void readUnregisteredQObjectProperty();
+ void writeUnregisteredQObjectProperty();
private:
// static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
@@ -5433,7 +5435,7 @@ void tst_qqmlecmascript::sequenceConversionWrite()
QVERIFY(seq != 0);
// we haven't registered QList<QPoint> as a sequence type, so writing shouldn't work.
- QString warningOne = qmlFile.toString() + QLatin1String(":16: Error: Cannot assign QJSValue to an unregistered type");
+ QString warningOne = qmlFile.toString() + QLatin1String(":16: Error: Cannot assign QJSValue to QList<QPoint>");
QTest::ignoreMessage(QtWarningMsg, warningOne.toLatin1().constData());
QMetaObject::invokeMethod(object, "performTest");
@@ -7767,6 +7769,80 @@ void tst_qqmlecmascript::qtbug_39520()
QCOMPARE(s.count('\n'), 1 * 1000 * 1000);
}
+class ContainedObject1 : public QObject
+{
+ Q_OBJECT
+};
+
+class ContainedObject2 : public QObject
+{
+ Q_OBJECT
+};
+
+class ObjectContainer : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(ContainedObject1 *object1 READ object1 WRITE setObject1)
+ Q_PROPERTY(ContainedObject2 *object2 READ object2 WRITE setObject2)
+public:
+ explicit ObjectContainer(QObject *parent = 0) :
+ QObject(parent),
+ mGetterCalled(false),
+ mSetterCalled(false)
+ {
+ }
+
+ ContainedObject1 *object1()
+ {
+ mGetterCalled = true;
+ return 0;
+ }
+
+ void setObject1(ContainedObject1 *)
+ {
+ mSetterCalled = true;
+ }
+
+ ContainedObject2 *object2()
+ {
+ mGetterCalled = true;
+ return 0;
+ }
+
+ void setObject2(ContainedObject2 *)
+ {
+ mSetterCalled = true;
+ }
+
+public:
+ bool mGetterCalled;
+ bool mSetterCalled;
+};
+
+void tst_qqmlecmascript::readUnregisteredQObjectProperty()
+{
+ qmlRegisterType<ObjectContainer>("Test", 1, 0, "ObjectContainer");
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("accessUnregisteredQObjectProperty.qml"));
+ QObject *root = component.create();
+ QVERIFY(root);
+
+ QMetaObject::invokeMethod(root, "readProperty");
+ QCOMPARE(root->property("container").value<ObjectContainer*>()->mGetterCalled, true);
+}
+
+void tst_qqmlecmascript::writeUnregisteredQObjectProperty()
+{
+ qmlRegisterType<ObjectContainer>("Test", 1, 0, "ObjectContainer");
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("accessUnregisteredQObjectProperty.qml"));
+ QObject *root = component.create();
+ QVERIFY(root);
+
+ QMetaObject::invokeMethod(root, "writeProperty");
+ QCOMPARE(root->property("container").value<ObjectContainer*>()->mSetterCalled, true);
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"