Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved How does Qt::connectiontype work?

    C++ Gurus
    3
    5
    2570
    Loading More Posts
    • 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
      Factao last edited by

      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?

      KillerSmath 1 Reply Last reply Reply Quote 0
      • KillerSmath
        KillerSmath @Factao last edited by

        @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 Reply Quote 1
        • F
          Factao @KillerSmath last edited by

          @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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            @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 Reply Quote 1
            • F
              Factao last edited by

              Thank you!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post