Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. How does Qt::connectiontype work?
QtWS25 Last Chance

How does Qt::connectiontype work?

Scheduled Pinned Locked Moved Solved C++ Gurus
5 Posts 3 Posters 3.7k Views
  • 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.
  • F Offline
    F Offline
    Factao
    wrote on last edited by
    #1

    Hello,

    I have this:

     QObject::connect(m_communicationCenter, &communicationCenter::globalCalRequested, m_motorCenter, &motorCenter::globalCalRequired, static_cast<Qt::ConnectionType>(Qt::UniqueConnection | Qt::DirectConnection));
        
    

    Yes, it is disgustingly long...

    Does this multiple connection type mean that the slot is going to be invoque only once directly on the thread of its QObject?

    KillerSmathK 1 Reply Last reply
    0
    • F Factao

      Hello,

      I have this:

       QObject::connect(m_communicationCenter, &communicationCenter::globalCalRequested, m_motorCenter, &motorCenter::globalCalRequired, static_cast<Qt::ConnectionType>(Qt::UniqueConnection | Qt::DirectConnection));
          
      

      Yes, it is disgustingly long...

      Does this multiple connection type mean that the slot is going to be invoque only once directly on the thread of its QObject?

      KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by
      #2

      @Factao
      From QObject Git File Documentation

      By default, a signal is emitted for every connection you make;
      two signals are emitted for duplicate connections. You can break
      all of these connections with a single disconnect() call.
      If you pass the Qt::UniqueConnection type, the connection will only
      be made if it is not a duplicate. If there is already a duplicate
      (exact same signal to the exact same slot on the same objects),
      the connection will fail and connect will return an invalid QMetaObject::Connection.

      \note Qt::UniqueConnections do not work for lambdas, non-member functions
      and functors; they only apply to connecting to member functions.

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      F 1 Reply Last reply
      1
      • KillerSmathK KillerSmath

        @Factao
        From QObject Git File Documentation

        By default, a signal is emitted for every connection you make;
        two signals are emitted for duplicate connections. You can break
        all of these connections with a single disconnect() call.
        If you pass the Qt::UniqueConnection type, the connection will only
        be made if it is not a duplicate. If there is already a duplicate
        (exact same signal to the exact same slot on the same objects),
        the connection will fail and connect will return an invalid QMetaObject::Connection.

        \note Qt::UniqueConnections do not work for lambdas, non-member functions
        and functors; they only apply to connecting to member functions.

        F Offline
        F Offline
        Factao
        wrote on last edited by
        #3

        @KillerSmath

        Thank you, but I understand the principe of the unique connection. My question was about how passing two connection type like I've done is interpreted. Will it be a direct connection that cannot be duplicated or something else?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Factao said in How does Qt::connectiontype work?:

          Qt::UniqueConnection

          From the doc:

          This is a flag that can be combined with any one of the above connection types, using a bitwise OR. When Qt::UniqueConnection is set, QObject::connect() will fail if the connection already exists (i.e. if the same signal is already connected to the same slot for the same pair of objects). This flag was introduced in Qt 4.6.
          

          So yes, you can combine that flag with one of the others.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • F Offline
            F Offline
            Factao
            wrote on last edited by
            #5

            Thank you!

            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