Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to call qml signal handler synchronously from cpp code from another thread?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rightaway717
    wrote on last edited by
    #1

    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:
    @
    //some.cpp

    signal void callQmlHandler();

    //some.qml
    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sandy.martel
      wrote on last edited by
      #2

      Connect with a BlockingQueuedConnection.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rightaway717
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved