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

How does Qt::connectiontype work?

Scheduled Pinned Locked Moved Solved C++ Gurus
5 Posts 3 Posters 3.8k 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.
  • F Offline
    F Offline
    Factao
    wrote on 21 Apr 2019, 02:07 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?

    K 1 Reply Last reply 21 Apr 2019, 03:17
    0
    • F Factao
      21 Apr 2019, 02:07

      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?

      K Offline
      K Offline
      KillerSmath
      wrote on 21 Apr 2019, 03:17 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 22 Apr 2019, 19:27
      1
      • K KillerSmath
        21 Apr 2019, 03:17

        @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 22 Apr 2019, 19:27 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 22 Apr 2019, 19:36 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 23 Apr 2019, 23:50 last edited by
            #5

            Thank you!

            1 Reply Last reply
            0

            2/5

            21 Apr 2019, 03:17

            • Login

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