How to communicate between two different QML components
Unsolved
QML and Qt Quick
-
I have two qml files i.e. main.qml & myComponent.qml
The main.qml invoke myComponent.qml like below:-
onTriggered: { var component = Qt.createComponent("myComponent.qml") if (component.status === Component.Ready) { . . . var window = component.createObject(root) if (window !== null){ window.show() } else { console.error("Error creating window object") } } else { console.error("Error loading component:", component.errorString()) } }
I've also defined Connection within the main.qml file to receive latest data from c++ like below:-
Connections { target: myObject // C++ object exposed to qml function onSignalRecv(response) { console.log(response) // Here i'm getting the latest data } }
Now i want to transfer this latest data from main.qml to myComponent.qml. Every time I receive data in onSignalRecv(..) i want to transfer it.
The myComponent.qml contains a ListView to show updated data and i want to update the data in realtime.
-
@johndummy Hi
define a signal in myComponent.qml
signal updateMyData(var newData)//adapt to your data type
then in main.qml after the creation of the myComponent add
```
onSignalRecv.connect( window.onSignalRecv ) // dont put arguments hereThen update your list in the updateMyData signal handler