From dfa5d2ddf1a9e9b3b610f2b17f48e54120bad935 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 6 May 2019 11:23:30 +1200 Subject: [PATCH] InteractiveWindow QML messaging example --- libraries/ui/src/InteractiveWindow.h | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/libraries/ui/src/InteractiveWindow.h b/libraries/ui/src/InteractiveWindow.h index 06712965e1..aee185fd4a 100644 --- a/libraries/ui/src/InteractiveWindow.h +++ b/libraries/ui/src/InteractiveWindow.h @@ -118,6 +118,44 @@ public slots: * } * @function InteractiveWindow.sendToQml * @param {string|object} message - The message to send to the QML page. + * @example Send and receive messages with a QML window. + * // JavaScript file. + * + * var qmlWindow = Desktop.createWindow(Script.resolvePath("QMLWindow.qml"), { + * title: "QML Window", + * size: { x: 400, y: 300 } + * }); + * + * qmlWindow.fromQml.connect(function (message) { + * print("Message received: " + message); + * }); + * + * Script.setTimeout(function () { + * qmlWindow.sendToQml("Hello world!"); + * }, 2000); + * + * Script.scriptEnding.connect(function () { + * qmlWindow.close(); + * }); + * @example + * // QML file, "QMLWindow.qml". + * + * import QtQuick 2.5 + * import QtQuick.Controls 1.4 + * + * Rectangle { + * + * function fromScript(message) { + * text.text = message; + * sendToScript("Hello back!"); + * } + * + * Label { + * id: text + * anchors.centerIn: parent + * text: "..." + * } + * } */ // Scripts can use this to send a message to the QML object void sendToQml(const QVariant& message);