diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2013-01-24 11:13:05 +0100 |
---|---|---|
committer | Pierre Rossi <pierre.rossi@gmail.com> | 2013-11-01 13:57:46 +0100 |
commit | 3dcb4ce965d0697a0b5e442d6bffe2936cc00f31 (patch) | |
tree | 38fe6097dd56950bac9f4dfaa61be47e565a295f /examples/qtobject | |
parent | e6802ced7665a650de9836cabd9e8753a5cfe859 (diff) | |
download | qtwebchannel-3dcb4ce965d0697a0b5e442d6bffe2936cc00f31.tar.gz |
Ensure proper signal connection and property binding.
When multiple signals or properties exist we must not fall into
the usual javascript closure trap - we used to only use the very
last signal/property of every object...
Change-Id: Ief24630cc4b4ce3935207a170711f66c3ef5d805
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'examples/qtobject')
-rw-r--r-- | examples/qtobject/qml/qtobject/index.html | 18 | ||||
-rw-r--r-- | examples/qtobject/testobject.cpp | 5 | ||||
-rw-r--r-- | examples/qtobject/testobject.h | 7 |
3 files changed, 23 insertions, 7 deletions
diff --git a/examples/qtobject/qml/qtobject/index.html b/examples/qtobject/qml/qtobject/index.html index ab1a542..20d3572 100644 --- a/examples/qtobject/qml/qtobject/index.html +++ b/examples/qtobject/qml/qtobject/index.html @@ -18,20 +18,26 @@ <body> <p>TestObject 1: <a href="#" onclick="testObject1.debugMe('Debugging!', function(result) { output(result); })">invoke method</a> - <a href="#" onclick="testObject1.prop1(function(value) { output(value); })">Get property</a> - <a href="#" onclick="testObject1.prop1 = 'Different property'; testObject1.prop1(function(value) { output(value); })">Set property</a> + <a href="#" onclick="testObject1.prop1(function(value) { output(value); })">Get property 1</a> + <a href="#" onclick="testObject1.prop1 = 'Different property'; testObject1.prop1(function(value) { output(value); })">Set property 1</a> + <a href="#" onclick="testObject1.prop2(function(value) { output(value); })">Get property 2</a> + <a href="#" onclick="testObject1.prop2 = 'Different property'; testObject1.prop2(function(value) { output(value); })">Set property 2</a> <a href="#" onclick="testObject1.timeout.connect(function() { output('timeout 1'); }); testObject1.startTimer(1000);">Timer</a> </p> <p>TestObject 2: <a href="#" onclick="testObject2.debugMe('Debugging!', function(result) { output(result); })">invoke method</a> - <a href="#" onclick="testObject2.prop1(function(value) { output(value); })">Get property</a> - <a href="#" onclick="testObject2.prop1 = 'Different property'; testObject2.prop1(function(value) { output(value); })">Set property</a> + <a href="#" onclick="testObject2.prop1(function(value) { output(value); })">Get property 1</a> + <a href="#" onclick="testObject2.prop1 = 'Different property'; testObject2.prop1(function(value) { output(value); })">Set property 1</a> + <a href="#" onclick="testObject2.prop2(function(value) { output(value); })">Get property 2</a> + <a href="#" onclick="testObject2.prop2 = 'Different property'; testObject2.prop2(function(value) { output(value); })">Set property 2</a> <a href="#" onclick="testObject2.timeout.connect(function() { output('timeout 2'); }); testObject2.startTimer(1000);">Timer</a> </p> <p>TestObject 3: <a href="#" onclick="testObject3.debugMe('Debugging!', function(result) { output(result); })">invoke method</a> - <a href="#" onclick="testObject3.prop1(function(value) { output(value); })">Get property</a> - <a href="#" onclick="testObject3.prop1 = 'Different property'; testObject3.prop1(function(value) { output(value); })">Set property</a> + <a href="#" onclick="testObject3.prop1(function(value) { output(value); })">Get property 1</a> + <a href="#" onclick="testObject3.prop1 = 'Different property'; testObject3.prop1(function(value) { output(value); })">Set property 1</a> + <a href="#" onclick="testObject3.prop2(function(value) { output(value); })">Get property 2</a> + <a href="#" onclick="testObject3.prop2 = 'Different property'; testObject3.prop2(function(value) { output(value); })">Set property 2</a> <a href="#" onclick="testObject3.timeout.connect(function() { output('timeout 3'); }); testObject3.startTimer(1000);">Timer</a> </p> <br/> diff --git a/examples/qtobject/testobject.cpp b/examples/qtobject/testobject.cpp index 75daa8d..260f1f6 100644 --- a/examples/qtobject/testobject.cpp +++ b/examples/qtobject/testobject.cpp @@ -19,3 +19,8 @@ void TestObject::setProp1(const QString& s) qWarning() << __func__ << p1; } +void TestObject::setProp2(const QString& s) +{ + p2 = s; + qWarning() << __func__ << p2; +} diff --git a/examples/qtobject/testobject.h b/examples/qtobject/testobject.h index 992247d..fe5043d 100644 --- a/examples/qtobject/testobject.h +++ b/examples/qtobject/testobject.h @@ -8,11 +8,15 @@ class TestObject : public QObject { Q_OBJECT Q_PROPERTY(QString prop1 READ prop1 WRITE setProp1) + Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2) public: explicit TestObject(QObject *parent = 0); - QString prop1() const { return p1 + objectName(); } + QString prop1() const { return "p1" + p1 + objectName(); } void setProp1(const QString& s); + QString prop2() const { return "p2" + p2 + objectName(); } + void setProp2(const QString& s); + signals: void timeout(); @@ -26,6 +30,7 @@ public slots: private: QString p1; + QString p2; QTimer timer; }; |