Use a variable in another file
-
Hello,
I have 2 files:
-Button.qml
-Other.qmlI have 2 variable in button.qml (clikedX and clikedY)and I would like to retrieve the value of these variables in other.qml
how should I do it?
Button.qml:
Rectangle { border.color: "black" radius:5 width:60 height:75 property var clikedX; property var clikedY; MouseArea{ anchors.fill:parent onClicked: { loader.source="other.qml" clikedX=parent.x clikedY=parent.y }
other.qml:
I would like here use the value of clikedX and ClikedY (so the value of parent.x and parent.y...)
-
Button.qml
Window { visible: true width: 640 height: 480 property real clikedX; property real clikedY; Rectangle { border.color: "black" radius:5 width:60 height:75 anchors.verticalCenter: parent.verticalCenter MouseArea{ anchors.fill:parent onClicked: { clikedX=parent.x clikedY=parent.y callOther.otherX=clikedX callOther.otherY=clikedY }} } Other{ id:callOther } }
Other.qml
Item { property real otherX; property real otherY; //youre code here }
-
@aktay So i have a variable in one file and i want use the value of this variable in an other file...
-
Maybe this is what you want :
Button.qml
Rectangle { border.color: "black" radius:5 width:60 height:75 property var clikedX; property var clikedY; signal btnClick() MouseArea{ anchors.fill: parent onClicked: { clikedX = mouseX clikedY = mouseY btnClick() } } }
Other.qml
Window { visible: true width: 640 height: 480 //title: qsTr("Hello World") Button { onBtnClick: { console.log(clikedX) console.log(clikedY) //do something with your clikedX/clikedY } } }
-
Maybe this is what you want :
Button.qml
Rectangle { border.color: "black" radius:5 width:60 height:75 property var clikedX; property var clikedY; signal btnClick() MouseArea{ anchors.fill: parent onClicked: { clikedX = mouseX clikedY = mouseY btnClick() } } }
Other.qml
Window { visible: true width: 640 height: 480 //title: qsTr("Hello World") Button { onBtnClick: { console.log(clikedX) console.log(clikedY) //do something with your clikedX/clikedY } } }
-
Hi @aktay
It's similar but a bit different, by using the btnClick() signal, I'm decoupling the Buttom.qml from Other.qml, that way Button.qml works as a generic button that can be used anywhere -
Hello,
I have 2 files:
-Button.qml
-Other.qmlI have 2 variable in button.qml (clikedX and clikedY)and I would like to retrieve the value of these variables in other.qml
how should I do it?
Button.qml:
Rectangle { border.color: "black" radius:5 width:60 height:75 property var clikedX; property var clikedY; MouseArea{ anchors.fill:parent onClicked: { loader.source="other.qml" clikedX=parent.x clikedY=parent.y }
other.qml:
I would like here use the value of clikedX and ClikedY (so the value of parent.x and parent.y...)
-
I create objects of "Button.qml" in the main.qml.
But I would like that when I click on this button that clikedX and clikedY contain the value of parent.x and parent.y.
Then after you can use the value of clikedX and clikedY in other.qml
But I do not create a Button in Other.qml ... @Yashpal @johngod @aktay -
I create objects of "Button.qml" in the main.qml.
But I would like that when I click on this button that clikedX and clikedY contain the value of parent.x and parent.y.
Then after you can use the value of clikedX and clikedY in other.qml
But I do not create a Button in Other.qml ... @Yashpal @johngod @aktay