Solved receive signal from other qml objec(these two object don't have parent-child relation but they have common parent.).
-
hello,i've been searching and still couldnt find answer. How can i send signal in one qml object and recive it in another object? considering that they dont have parent child relation. but they have common parents.
-
-
@raven-worx
thanks
but what if they are not in same file?
for example:// common parent item { Child1 {} Child2 {} } //Child1.qml Item { id:child1 Rectangle { id:rec1 } } //Child2.qml Item { id:child2 Rectangle { id:rec2 MouseArea { anchors.fill: parent onClicked: { "Some Code to change rec1 color" } } } }
how can I change color of rec1 from onClicked in rec2?
-
@PooyaSis said in receive signal from other qml objec(these two object don't have parent-child relation but they have common parent.).:
how can I change color of rec1 from onClicked in rec2?
Item { Child1 { id: child1 } Child2 { id: child2 } Component.onComplete: child1.mySignal.connect(child2.mySlot) } //Child1.qml Item { id: base function mySlot() { rec1.color = "red" } Rectangle { id:rec1 } } //Child2.qml Item { id: base signal mySignal() Rectangle { id:rec2 MouseArea { anchors.fill: parent onClicked: base.mySignal() } }
-
@raven-worx thanks for your help. solved.