summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-05-11 03:33:09 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-05-11 03:33:09 (GMT)
commit62ca28e8bfd469a227f7099eb0c2e76b0b2cb2e8 (patch)
treea5f352d68c6fad08fd6fbf0ecffe107a202eb74a /tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp
parent33b6ff260ff5454bf65a307535994d168d0dd10a (diff)
downloadQt-62ca28e8bfd469a227f7099eb0c2e76b0b2cb2e8.zip
Qt-62ca28e8bfd469a227f7099eb0c2e76b0b2cb2e8.tar.gz
Qt-62ca28e8bfd469a227f7099eb0c2e76b0b2cb2e8.tar.bz2
Detect binding loops.
Don't crash when a looping binding has been established. Instead, print a warning and stop looping.
Diffstat (limited to 'tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp')
-rw-r--r--tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp39
1 files changed, 37 insertions, 2 deletions
diff --git a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp
index 0875690..ca840f4 100644
--- a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp
+++ b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp
@@ -7,7 +7,7 @@ class MyQmlObject : public QObject
Q_OBJECT
Q_PROPERTY(bool trueProperty READ trueProperty)
Q_PROPERTY(bool falseProperty READ falseProperty)
- Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty)
+ Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged)
public:
MyQmlObject(): m_methodCalled(false), m_methodIntCalled(false) {}
@@ -15,7 +15,13 @@ public:
bool falseProperty() const { return false; }
QString stringProperty() const { return m_string; }
- void setStringProperty(const QString &s) { m_string = s; }
+ void setStringProperty(const QString &s)
+ {
+ if (s == m_string)
+ return;
+ m_string = s;
+ emit stringChanged();
+ }
bool methodCalled() const { return m_methodCalled; }
bool methodIntCalled() const { return m_methodIntCalled; }
@@ -24,6 +30,7 @@ public:
signals:
void basicSignal();
void argumentSignal(int a, QString b, qreal c);
+ void stringChanged();
public slots:
void method() { m_methodCalled = true; }
@@ -41,6 +48,22 @@ private:
QML_DECLARE_TYPE(MyQmlObject);
QML_DEFINE_TYPE(MyQmlObject,MyQmlObject);
+class MyQmlContainer : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QList<MyQmlContainer*>* children READ children)
+public:
+ MyQmlContainer() {}
+
+ QList<MyQmlContainer*> *children() { return &m_children; }
+
+private:
+ QList<MyQmlContainer*> m_children;
+};
+
+QML_DECLARE_TYPE(MyQmlContainer);
+QML_DEFINE_TYPE(MyQmlContainer,MyQmlContainer);
+
class tst_qmlbindengine : public QObject
{
Q_OBJECT
@@ -51,6 +74,7 @@ private slots:
void boolPropertiesEvaluateAsBool();
void methods();
void signalAssignment();
+ void bindingLoop();
private:
QmlEngine engine;
@@ -117,6 +141,17 @@ void tst_qmlbindengine::methods()
QCOMPARE(object->methodIntCalled(), true);
}
}
+#include <QDebug>
+void tst_qmlbindengine::bindingLoop()
+{
+ QmlComponent component(&engine, "MyQmlContainer { children : [ "\
+ "MyQmlObject { id: Object1; stringProperty: \"hello\" + Object2.stringProperty }, "\
+ "MyQmlObject { id: Object2; stringProperty: \"hello\" + Object1.stringProperty } ] }");
+ //### ignoreMessage doesn't seem to work here
+ //QTest::ignoreMessage(QtWarningMsg, "QML MyQmlObject (unknown location): Binding loop detected for property \"stringProperty\"");
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+}
QTEST_MAIN(tst_qmlbindengine)