Solved Communication between Qml Objects
-
@Bhushan_Sure said in Communication between Qml Objects:
is there any way ?
Yes.
One{ id:o } Two{ id:t } Component.onCompleted : { o.signalName.connect(t.functionName) }
or
One{ id:o onSignalName : { t.functionNAme()} } Two{ id:t }
-
@J.Hilk where do i have to define Mysignal ?
-
@Bhushan_Sure
inside One.qmlsignal mySignal()
-
@J.Hilk @LeLev Ok i will try both the way.
-
@Bhushan_Sure I also use this method:
Let say you wanna open other window when clicked:onClicked{
var component = Qt.createComponent("two.qml")
var window = component.createObject('oneqml mainscope id')
window.show()
} -
oneqml.qml
Rectangle{ id:one height: 400 width: 400 color: "red" signal mysignal MouseArea { anchors.fill: parent onClicked: { mysignal() } } onMysignal:{ two.bhushan() } }
twoqml.qml
Rectangle { id:two height: 400 width: 400 color: "yellow" function bhushan() { console.log("Bhushan") } }
error is two is not defined
What i have done wrong ? -
@Bhushan_Sure said in Communication between Qml Objects:
onMysignal
the reaction to mySignal needs to be inside the parent - where you instantiate One.qml object
-
-
@Bhushan_Sure said in Communication between Qml Objects:
But i don't want to instantiate one.qml into two.qml because
you don't have to .. see my first compment
... One{ id:o onSignalName : { t.functionNAme()} } Two{ id:t } ...
-
@Bhushan_Sure Okey you only need that function do this exactly:(Two 's 't' should be upper case be careful. You also needto recreate your two.qml file as Two.qml
//oneqml
//up the mousearea
Two{
id:caller
}onClicked{
caller.bhushan()
} -