How to call qml signal handler synchronously from cpp code from another thread?

  • Hi,

    I know that normally you wouldn't do what I'm asking. I understand that these two layers should be separate and connect via signal/slot mechanism, which maybe asynchronous if we deal with threads.

    Understanding this, I still need to call qml signal handler synchronously from SG thread. Qml objects live in GUI thread, thus emitting a signal from SG thread (particularly from updatePaintNode() method) results in asynchronous event.

    I have read docs and I have no problem calling qml function from cpp. For example:
    QMetaObject::invokeMethod(this, "myNiceQmlFunction", Qt::DirectConnection);

    But imagine this:

    signal void callQmlHandler();

    MyObject {
    onCallQmlHandler: {
    // do something right now

    I don't know how to call onCallQmlHandler synchronously via QMetaObject::invokeMethod.
    I don't create qml object from code and at this point in cpp I don't have access to qml component to look for its children, find MyObject there by name and call its handler (if it is possible). Anyways, this is not a beautiful way to do so.

    Does anyone know if I miss the right syntax to call signal handler via QMetaObject::invokeMethod or it is not possible at all? Any ideas?

    Thank you

  • Connect with a BlockingQueuedConnection.

  • bq. Connect with a BlockingQueuedConnection

    AFAIK you can not connect to a signal handler manually. Connection is generated by qml, qml creates signal handler and I don't know a way to change that.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.