aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-09-01 16:14:30 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-09-07 16:57:16 +0200
commitd3b3fef5a878d7fd53de6a9f9fff196a273930e3 (patch)
tree76b96ff3d6f34a01bf4a9881dd75626921c49daf /tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
parent5cda89ce030ff5fbc9e95be1b9ca74adb401a9d7 (diff)
Qml: Allow const and non-const QObjectWrappers to coexist
We can access the same QObject in const and non-const contexts. Both should be possible. Store the const objectwrapper in m_multiplyWrappedObjects. That's somewhat slow, but const QObjects are rather rare. Pick-to: 6.4 Fixes: QTBUG-98479 Change-Id: I047afc121f5c29b955cd833e0a2c8299fc52b021 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp61
1 files changed, 56 insertions, 5 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 4cc056a425..63cf12a5a2 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -9945,14 +9945,65 @@ void tst_qqmlecmascript::cmpInThrows()
QCOMPARE(stacktrace.at(0), QStringLiteral("%entry:14:-1:file:foo.js"));
}
+class FrozenFoo : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString name MEMBER m_name NOTIFY nameChanged)
+
+public:
+ FrozenFoo(QObject *parent = nullptr) : QObject(parent) {}
+ QString name() const { return m_name; }
+
+signals:
+ void nameChanged();
+
+private:
+ QString m_name{ "Foo" };
+};
+
+class FrozenObjects : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(FrozenFoo *fooMember READ fooMember CONSTANT);
+ Q_PROPERTY(const FrozenFoo *fooMemberConst READ fooMemberConst CONSTANT);
+ Q_PROPERTY(FrozenFoo *fooMember2 READ fooMember2 CONSTANT);
+
+public:
+ FrozenObjects(QObject *parent = nullptr) : QObject(parent) {}
+
+ Q_INVOKABLE void triggerSignal() { emit fooMember2Emitted(&m_fooMember2); }
+
+ FrozenFoo *fooMember() { return &m_fooMember; }
+ FrozenFoo *fooMember2() { return &m_fooMember2; }
+
+signals:
+ void fooMember2Emitted(const FrozenFoo *fooMember2);
+
+private:
+ const FrozenFoo *fooMemberConst() const { return &m_fooMember; }
+
+ FrozenFoo m_fooMember;
+ FrozenFoo m_fooMember2;
+};
+
void tst_qqmlecmascript::frozenQObject()
{
+ qmlRegisterType<FrozenObjects>("test", 1, 0, "FrozenObjects");
+
QQmlEngine engine;
- QQmlComponent component(&engine, testFileUrl("frozenQObject.qml"));
- QScopedPointer<QObject> root(component.create());
- QVERIFY2(root, qPrintable(component.errorString()));
- QVERIFY(root->property("caughtException").toBool());
- QVERIFY(root->property("nameCorrect").toBool());
+ QQmlComponent component1(&engine, testFileUrl("frozenQObject.qml"));
+ QScopedPointer<QObject> root1(component1.create());
+ QVERIFY2(root1, qPrintable(component1.errorString()));
+ QVERIFY(root1->property("caughtException").toBool());
+ QVERIFY(root1->property("nameCorrect").toBool());
+
+ QQmlComponent component2(&engine, testFileUrl("frozenQObject2.qml"));
+ QScopedPointer<QObject> root2(component2.create());
+ FrozenObjects *frozenObjects = qobject_cast<FrozenObjects *>(root2.data());
+ QVERIFY2(frozenObjects, qPrintable(component2.errorString()));
+ QVERIFY(frozenObjects->property("caughtSignal").toBool());
+ QCOMPARE(frozenObjects->fooMember()->name(), QStringLiteral("Jane"));
+ QCOMPARE(frozenObjects->fooMember2()->name(), QStringLiteral("Jane"));
}
struct ConstPointer : QObject