aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-03-23 21:32:38 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2020-03-30 14:18:18 +0200
commitdff7689a016d63fbaf1abc6f00a768dbfb8ec095 (patch)
tree6f0b67ce5d6dec279c0bbf62f014955cd0f25e32 /tests/auto/qml/qqmlecmascript
parent9f2c5aa2efd24507f4508889911873bc1c9d301e (diff)
Add support for binding directly to QProperty instances
Avoid going through externally managed bindings and instead allocate a more lightweight property binding. It's basically a QQmlJavaScriptExpression and one pointer plus the overhead of QPropertyBindingPrivate. Change-Id: I1530330926d351b61f2b3bbad39301c628a8bef1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/bindingOnQProperty.qml7
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.cpp2
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.h9
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp17
4 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/bindingOnQProperty.qml b/tests/auto/qml/qqmlecmascript/data/bindingOnQProperty.qml
new file mode 100644
index 0000000000..1bd043d9df
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/bindingOnQProperty.qml
@@ -0,0 +1,7 @@
+import Qt.test 1.0
+ClassWithQProperty {
+ property int externalValue
+ value: {
+ return externalValue
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp
index 89887fe6c3..606860379e 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.cpp
+++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp
@@ -548,6 +548,8 @@ void registerTypes()
qmlRegisterType<FloatingQObject>("Qt.test", 1, 0, "FloatingQObject");
qmlRegisterType<ClashingNames>("Qt.test", 1, 0, "ClashingNames");
+
+ qmlRegisterType<ClassWithQProperty>("Qt.test", 1, 0, "ClassWithQProperty");
}
#include "testtypes.moc"
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h
index 03e3262e7b..415e884eb8 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.h
+++ b/tests/auto/qml/qqmlecmascript/testtypes.h
@@ -44,6 +44,7 @@
#include <QtCore/qjsonarray.h>
#include <QtCore/qjsonobject.h>
#include <QtCore/qjsonvalue.h>
+#include <QtCore/qproperty.h>
#include <QtQml/qjsvalue.h>
#include <QtQml/qqmlscriptstring.h>
#include <QtQml/qqmlcomponent.h>
@@ -1726,6 +1727,14 @@ public:
Q_INVOKABLE bool clashes() const { return true; }
};
+struct ClassWithQProperty : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int value)
+public:
+ QProperty<int> value;
+};
+
void registerTypes();
#endif // TESTTYPES_H
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index b3e4296a13..fbb344f9a0 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -381,6 +381,7 @@ private slots:
void getThisObject();
void semicolonAfterProperty();
void hugeStack();
+ void bindingOnQProperty();
void gcCrashRegressionTest();
@@ -9281,6 +9282,22 @@ void tst_qqmlecmascript::gcCrashRegressionTest()
QCOMPARE(process.exitCode(), 0);
}
+void tst_qqmlecmascript::bindingOnQProperty()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("bindingOnQProperty.qml"));
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+ QScopedPointer<QObject> test(component.create());
+ test->setProperty("externalValue", 42);
+ QCOMPARE(test->property("value").toInt(), 42);
+ test->setProperty("externalValue", 100);
+ QCOMPARE(test->property("value").toInt(), 100);
+
+ QVERIFY(qobject_cast<ClassWithQProperty*>(test.data()));
+ QProperty<int> &qprop = static_cast<ClassWithQProperty*>(test.data())->value;
+ QVERIFY(qprop.hasBinding());
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"