How to interact in between two QML screens?
-
How to interact in between two QML screens?
I am creating new QML component/screen by using "createComponent" and "createObject".@var component = Qt.createComponent("testQml.qml");
var sprite = component.createObject(parentWindow, {"x":0, "y":0});
if(sprite == null)
{
console.log("Error creating component\n");
return;
}
console.log("Screen Created\n");
// Send some data to the newly created screen
@I have some data that I need to pass it to the newly created screen before it displays the UI components.
I need two way communication in between child and the parent screen.
I also need to call some function of the parent QML screen from child screen.how it is done in the QML?
Thanks.
-
May be you can use properties and signals to pass data around ?
-
Can you please provide one example for this (using two qml/js files).
One way I found is common javascript file in between two QML files and from QML file accessing global key value pares (global array) to send and receive parameters across two QML files. -
Here.. Using a common Javascript file to share data.
Global.js
@
.pragma library
var sharedVariable = null;
@Your Screen1.qml
@
import "Global.js" as GlobalJSRectangle {
MouseArea {
anchors.fill:parent
onClicked: GlobalJS.sharedVariable = "This is shared data";
}
}
@Your Screen2.qml
@
import "Global.js" as GlobalJSRectangle {
Text {text: GlobalJS.sharedVariable
}
}
@ -
Thanks for the reply