diff options
Diffstat (limited to 'examples/qmlapp/qmlapp.qml')
-rw-r--r-- | examples/qmlapp/qmlapp.qml | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/examples/qmlapp/qmlapp.qml b/examples/qmlapp/qmlapp.qml index f82973e..6599bf1 100644 --- a/examples/qmlapp/qmlapp.qml +++ b/examples/qmlapp/qmlapp.qml @@ -43,48 +43,55 @@ import QtQuick 2.0 import Qt.labs.WebChannel 1.0 import QtWebKit 3.0 +import QtWebKit.experimental 1.0 Rectangle { - width: 1000 - height: 360 + width: 500 + height: 600 WebChannel { id: webChannel - onExecute: { - console.log(requestData); - var data = JSON.parse(requestData); - txt.text = data.a; - response.send(JSON.stringify({b:'This is a response from QML'})); + onRawMessageReceived: { + console.log(rawMessage); + var msg = JSON.parse(rawMessage); + editor.text += msg.data.a + "\n"; + sendMessage("b", "This is a response from QML"); } - onBaseUrlChanged: { + onInitialized: { console.log(baseUrl); } } - WebView { - id: webView - url: "index.html?webChannelBaseUrl=" + webChannel.baseUrl; - anchors.top: txt.bottom - height: 2000 - width: 2000 - } - TextEdit { - width: 1000 - height: 100 + text: "enter data here\n" id: editor anchors.top: parent.top + width: parent.width + height: 400 } + Text { id: txt - text: "Click" anchors.top: editor.bottom + width: parent.width + height: 100 + text: "Click to send message to HTML client" MouseArea { anchors.fill: parent onClicked: { - webChannel.broadcast("foobar", JSON.stringify(editor.text)); + webChannel.sendMessage("foobar", editor.text); } } } + + WebView { + id: webView + width: parent.width + anchors.top: txt.bottom + height: 100 + url: "index.html?webChannelBaseUrl=" + webChannel.baseUrl; + experimental.preferences.developerExtrasEnabled: true + } + } |