Not able to receive signal in more than one QML file
-
Hi all,
I am new to Qt and QML. Signal emitted from cpp file is not received by two of my QML files. Though I am able to receive the signal in one QML but why it is not received by another QML.I have used
engine.rootContext()->setContextProperty("my module",&myfile) in main.cpp and using connections in both qml file
Connections{
target: myfile
function onSignal1() {
}
}
It works in one file.Thanks in advance.
-
Hi all,
I am new to Qt and QML. Signal emitted from cpp file is not received by two of my QML files. Though I am able to receive the signal in one QML but why it is not received by another QML.I have used
engine.rootContext()->setContextProperty("my module",&myfile) in main.cpp and using connections in both qml file
Connections{
target: myfile
function onSignal1() {
}
}
It works in one file.Thanks in advance.
-
Hi all,
I am new to Qt and QML. Signal emitted from cpp file is not received by two of my QML files. Though I am able to receive the signal in one QML but why it is not received by another QML.I have used
engine.rootContext()->setContextProperty("my module",&myfile) in main.cpp and using connections in both qml file
Connections{
target: myfile
function onSignal1() {
}
}
It works in one file.Thanks in advance.
@Gery said in Not able to receive signal in more than one QML file:
You register
my moduleas object name, but you try to connect tomyfile. That might be one part of the problem. Another (just a guess) is that when signal is sent, only one of the QML files is open and loaded by the engine. So the other one does not receive the signal because it's not a live object.engine.rootContext()->setContextProperty("my module",&myfile) Connections{ target: myfile function onSignal1() { } } -
@Gery said in Not able to receive signal in more than one QML file:
You register
my moduleas object name, but you try to connect tomyfile. That might be one part of the problem. Another (just a guess) is that when signal is sent, only one of the QML files is open and loaded by the engine. So the other one does not receive the signal because it's not a live object.engine.rootContext()->setContextProperty("my module",&myfile) Connections{ target: myfile function onSignal1() { } } -
@sierdzio sorry for typo, I have used myModule only and its working in one. Is there any work around to work with same live object, is it using singleton object, I am bit stuck on it.
@Gery from the point of view of the QML engine, your root context property already is a singleton (it is a single, global object, visible from all QML code).
If your other QML file is not loaded when signal is emitted, you have 2 options I think:
- Load the file earlier (maybe with a Loader? It's really hard to say for me since I don't know your code)
- make sure the data from signal is available in your
myModuleobject later, when the other QML file needs it. For example,myModulecan have a Q_PROPERTY which holds the data. Then QML can always access it easily