Passing parameters between windows
-
hello everybody
I'm new to the forum!I would like to know if is it possible to pass parameters between windows with qml.
this event of the main window:
@MouseArea {
anchors.fill: parent
onClicked: {
Qt.createComponent("detail_dialog.qml").createObject(mainWindow, {});
}
}@and this is the detail_dialog.qml:
@import QtQuick 2.0
Item {
Component.onCompleted: console.log(text)
id: detailDialog
anchors.fill: parent
PropertyAnimation {
target: detailDialog
property: "opacity"
duration: 400
from: 0
to: 1
easing.type: Easing.InOutQuad
running: true
}
Rectangle {
id: dialogWindow
width: 200
height: 200
radius: 10
border.color: "black"
anchors.centerIn: parent
Text {
anchors.centerIn: parent
text: "Hello"
}
MouseArea{
anchors.fill: parent
onClicked: {
detailDialog.destroy()
}
}
}
}
@is it possible?
-
Hello and welcome to devnet,
i would go ahead and use signals for that. For example:
- Creating the component: @var component = Qt.createComponent("detail_dialog.qml.qml");
dialog = component.createObject(root);
dialog.show();@ - Creating the signals in your detail_dialog.qml, for example: signal mySignal()
- Accessing the signals with for example: dialog.onMySignal()
Havn't tested it out yet but it should theoretically work,
- Creating the component: @var component = Qt.createComponent("detail_dialog.qml.qml");
-
ok I solved without knowing it.
the data is from this javascript function.
in the dialog was enough for me to do so:@
Text {
anchors.centerIn: parent
text: "AUTORE: " + author + "\n" + "EDITORE: " + editor
}
@this is the javascript function, and is called in the main.qml
@
function load() {
listModelJson.clear();
var xhr = new XMLHttpRequest();
xhr.open("GET","http://www.sito.com/file.php", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == xhr.DONE) {
if (xhr.status == 200) {
var jsonObject = JSON.parse(xhr.responseText);
for (var i in jsonObject) {
listModelJson.append({
"title" : jsonObject[i].title,
"author" : jsonObject[i].author,
"editor" : jsonObject[i].editor
});
}
}
}
}
xhr.send();
}
@thanks!!