Solved Queued connection from QML?
-
Hi,
I would like to communicate with QThreads from QML.
Normally I would use a QueuedConnection for that which seems not to be available in QML.Is there a way to invoke c++ class methods in a queued way?
I know that I can put a c++ class in the middle.
So put all methods which should be invoked from qml as slots to that class and emit queued signals from there to the real thread.Thanks :-)
-
hi @robro
unfortunatly, there's no way to force a queued connection, the way you want it. At leas not that I know of.
I think the call of cpp classes from QML and vice versa are already queued be default, but I might be wrong here.
However there's a simple workaround, define a signal in your c++ class, make it accesable by qml via
Q_INVOKABLE
and make a normal QObject::connection inside your class constructor.
Than simply invoke that signal from the QML side. -
Thanks for this really nice workaround!
It is working fine :-) -
Sorry... I have to reopen this thread.
With the described workaround I can make a connection from QML to C++, but how can I make it work the other way round?
Usually I would do something like:
Connections { target: classInAnotherThread; onSignalABC: { //console.log("Got signal") }
Here I now get the error that the QML engine is in another thread.
-
hi @robro
I would say, you solve this with the same workaround.
you can QObject::connect, 2 signals to gether. Use that and forward the signal to the parent, not threaded class to than pass it to qml.
-
This works fine!
Thank you very much :-) -