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. Queued connection from QML?
Forum Updated to NodeBB v4.3 + New Features

Queued connection from QML?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 3.4k 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
    robro
    wrote on last edited by
    #1

    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 :-)

    J.HilkJ 1 Reply Last reply
    0
    • R robro

      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 :-)

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      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.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

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

        Thanks for this really nice workaround!
        It is working fine :-)

        1 Reply Last reply
        0
        • R Offline
          R Offline
          robro
          wrote on last edited by
          #4

          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.

          J.HilkJ 1 Reply Last reply
          0
          • R robro

            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.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            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.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            3
            • R Offline
              R Offline
              robro
              wrote on last edited by
              #6

              This works fine!
              Thank you very much :-)

              1 Reply Last reply
              0
              • J.HilkJ J.Hilk referenced this topic on

              • Login

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