Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Synchronous signals between C++ and QML
scztt last edited by
I'm running into a problem (limitation) when firing signals between C++ and QML code - here's my scenario:
- A QML UI event (mouse click) fires a signal that is being listened to by some C++ object.
- The C++ objects, in turn, fire some more signals which are being listened to by QML objects (the bindings for these signals are done in QML).
I'm seeing, in #2, that when I emit the signals in C++ they are NOT being processed immediately in QML. As far as I can tell, they are using something equivalent to
QueuedConnection, e.g. they are being processed during the next run through the event loop. I see my c++
emitreturn immediately, and when the QML-side code responds, I see it doing so from a stack For me, this is a problem, because it leaves both my front-end and back-end in an unresolved state: I need all of the connected signals to be processed before I can move on.
In C++ Qt code, this can easily be resolved by doing something like:
QObject::connect(sender, "syncSignal", receiver, "onSignal", Qt::DirectConnection). But - as far as I can tell the QML
Connectionobject doesn't support specifying connection types.
Is there a way I can synchronously signal QML code from C++? Is there another way of generating a binding in QML that might allow this? It appears that, once I've crossed the boundary into C++ code at all, it's impossible for me to jump back to QML without losing my stack context. Am I missing something obvious on the QML side here? Is there a way I can force a signal to be handled synchronously?
Kai Nickel last edited by