summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorNo'am Rosenthal <noam.rosenthal@nokia.com>2011-08-09 16:12:44 -0700
committerNo'am Rosenthal <noam.rosenthal@nokia.com>2011-08-09 16:12:44 -0700
commit2125fddc87f78ca79317912fb497952f0a01bb81 (patch)
tree25cdf2acfad6a2f0c2ebbf96436ede18fed1fc38 /examples
parentde80f36191c4c2d538af722083d8460d8603a16b (diff)
downloadqtwebchannel-2125fddc87f78ca79317912fb497952f0a01bb81.tar.gz
Change the invokeMethod syntax to allow for a return callback
Diffstat (limited to 'examples')
-rw-r--r--examples/qtobject/qml/qtobject/index.html2
-rw-r--r--examples/qtobject/qml/qtobject/qtobject.js11
-rw-r--r--examples/qtobject/testobject.cpp3
-rw-r--r--examples/qtobject/testobject.h2
4 files changed, 14 insertions, 4 deletions
diff --git a/examples/qtobject/qml/qtobject/index.html b/examples/qtobject/qml/qtobject/index.html
index b177522..d79fd7e 100644
--- a/examples/qtobject/qml/qtobject/index.html
+++ b/examples/qtobject/qml/qtobject/index.html
@@ -12,7 +12,7 @@
</script>
</head>
<body>
- <a href="#" onclick="testObject.debugMe('Debugging!')">invoke method</a>
+ <a href="#" onclick="testObject.debugMe('Debugging!', function(result) { output(result); })">invoke method</a>
<a href="#" onclick="testObject.prop1(function(value) { output(value); })">Get property</a>
<a href="#" onclick="testObject.prop1 = 'Different property'; testObject.prop1(function(value) { output(value); })">Set property</a>
<a href="#" onclick="testObject.timeout.connect(function() { output('timeout'); }); testObject.startTimer(1000);">Timer</a>
diff --git a/examples/qtobject/qml/qtobject/qtobject.js b/examples/qtobject/qml/qtobject/qtobject.js
index 0545737..f0fe370 100644
--- a/examples/qtobject/qml/qtobject/qtobject.js
+++ b/examples/qtobject/qml/qtobject/qtobject.js
@@ -69,7 +69,16 @@ window.onload = function() {
methodsAndSignals.push(data.signals[i]);
methodsAndSignals.forEach(function(method) {
- object[method] = function(args, callback) {
+ object[method] = function() {
+ var args = [];
+ var callback;
+ for (var i = 0; i < arguments.length; ++i) {
+ if (typeof arguments[i] == "function")
+ callback = arguments[i];
+ else
+ args.push(arguments[i]);
+ }
+
webChannel.exec(JSON.stringify({type: "Qt.invokeMethod", object: objectName, method: method, args: args}), function(response) {
if (response.length)
(callback)(JSON.parse(response));
diff --git a/examples/qtobject/testobject.cpp b/examples/qtobject/testobject.cpp
index 5d2f3ce..f13c5ab 100644
--- a/examples/qtobject/testobject.cpp
+++ b/examples/qtobject/testobject.cpp
@@ -7,9 +7,10 @@ TestObject::TestObject(QObject *parent) :
connect(&timer, SIGNAL(timeout()), this, SIGNAL(timeout()));
}
-void TestObject::debugMe(const QString& data)
+QString TestObject::debugMe(const QString& data)
{
qWarning() << data;
+ return "OK";
}
void TestObject::setProp1(const QString& s)
diff --git a/examples/qtobject/testobject.h b/examples/qtobject/testobject.h
index de60f36..93aa227 100644
--- a/examples/qtobject/testobject.h
+++ b/examples/qtobject/testobject.h
@@ -22,7 +22,7 @@ public slots:
timer.start(millis);
}
- void debugMe(const QString& data);
+ QString debugMe(const QString& data);
private:
QString p1;