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. Specify Qt::QueuedConnection for connections made via the Connections QML type

Specify Qt::QueuedConnection for connections made via the Connections QML type

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 3.3k 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.
  • vikramgV Offline
    vikramgV Offline
    vikramg
    wrote on last edited by
    #1

    I have an application where signals are sent between QML and a worker running in a separate QThread. When connections are made in C++ via QObject::connect, everything works as expected. I have not specified a ConnectionType; presumably the default of AutoConnection does the right thing and uses QueuedConnection since the receiver is in a different thread.

    My code could get cleaned up vastly if I could just connect via the Connections QML type as demonstrated here: https://www.wisol.ch/w/articles/2014-12-15-qt-signal-slots-qml-cpp/. I had hoped that such connections would also default to using AutoConnection, but it appears that that is not so. I'm seeing warnings like QObject::killTimer: Timers cannot be stopped from another thread which suggest that a DirectConnection is being made.

    Is there any way to specify QueuedConnection in a Connections object?

    J.HilkJ 1 Reply Last reply
    0
    • vikramgV vikramg

      I have an application where signals are sent between QML and a worker running in a separate QThread. When connections are made in C++ via QObject::connect, everything works as expected. I have not specified a ConnectionType; presumably the default of AutoConnection does the right thing and uses QueuedConnection since the receiver is in a different thread.

      My code could get cleaned up vastly if I could just connect via the Connections QML type as demonstrated here: https://www.wisol.ch/w/articles/2014-12-15-qt-signal-slots-qml-cpp/. I had hoped that such connections would also default to using AutoConnection, but it appears that that is not so. I'm seeing warnings like QObject::killTimer: Timers cannot be stopped from another thread which suggest that a DirectConnection is being made.

      Is there any way to specify QueuedConnection in a Connections object?

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

      @vikramg
      yes of course, the connection typ is always the 5th parameter. Most of the time you don't write it down, as it has a preset of Qt::AutoConnection

      connect(qmlObj, SIGNAL(someSignal(QVariant)), cppObj, SLOT(someSlot(QVariant)),Qt::QueuedConnection );
      

      should work just fine,


      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.

      vikramgV 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @vikramg
        yes of course, the connection typ is always the 5th parameter. Most of the time you don't write it down, as it has a preset of Qt::AutoConnection

        connect(qmlObj, SIGNAL(someSignal(QVariant)), cppObj, SLOT(someSlot(QVariant)),Qt::QueuedConnection );
        

        should work just fine,

        vikramgV Offline
        vikramgV Offline
        vikramg
        wrote on last edited by
        #3

        @J.Hilk
        No, I'm talking specifically about not using the QObject::connect method; instead using a Connections object in QML, as shown in the link in my original post:

        Window {
          Connections {
            target: receiver
            onSendToQml: {
            console.log("Received in QML from C++: " + count)
            }
          }
          MouseArea {
            anchors.fill: parent
            onClicked: {
              receiver.receiveFromQml(42);
            }
          }
        }
        

        In this case, no explicit connect calls are needed; they get arranged for you via the Connections object instantiation in QML. receiveFromQml() automatically invokes a slot from QML to C++ and the sendToQml() member function of the Receiver class automatically results in an onSendToQml() signal in QML.

        In this kind of implicit signal/slot connection, is there a way to specify QueuedConnection?

        J.HilkJ 1 Reply Last reply
        0
        • vikramgV vikramg

          @J.Hilk
          No, I'm talking specifically about not using the QObject::connect method; instead using a Connections object in QML, as shown in the link in my original post:

          Window {
            Connections {
              target: receiver
              onSendToQml: {
              console.log("Received in QML from C++: " + count)
              }
            }
            MouseArea {
              anchors.fill: parent
              onClicked: {
                receiver.receiveFromQml(42);
              }
            }
          }
          

          In this case, no explicit connect calls are needed; they get arranged for you via the Connections object instantiation in QML. receiveFromQml() automatically invokes a slot from QML to C++ and the sendToQml() member function of the Receiver class automatically results in an onSendToQml() signal in QML.

          In this kind of implicit signal/slot connection, is there a way to specify QueuedConnection?

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

          @vikramg oh, you want to go that route.
          AFAIK theres no such thing. But you could connect your slot to a singleshot timer that basically emulates a QueuedConnection:

          Connections {
              target: receiver
              onSendToQml: { QueuedTimer.start()}
            }
          
          Timer {
              id: QueuedTimer
              interval: 1
              onTriggered:{     console.log("Received in QML from C++: " + count) }
          }
          

          But mabe someone else knows more about this topic.


          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.

          vikramgV 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @vikramg oh, you want to go that route.
            AFAIK theres no such thing. But you could connect your slot to a singleshot timer that basically emulates a QueuedConnection:

            Connections {
                target: receiver
                onSendToQml: { QueuedTimer.start()}
              }
            
            Timer {
                id: QueuedTimer
                interval: 1
                onTriggered:{     console.log("Received in QML from C++: " + count) }
            }
            

            But mabe someone else knows more about this topic.

            vikramgV Offline
            vikramgV Offline
            vikramg
            wrote on last edited by
            #5

            Thanks @J.Hilk
            Yes, the C++ connect calls work fine; I did want to try with a Connections object in QML because that would clean up many connect calls in C++.

            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