Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. slot will be called multi-times if connect() multi-times, is there any way to check this error?
Forum Updated to NodeBB v4.3 + New Features

slot will be called multi-times if connect() multi-times, is there any way to check this error?

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 2.0k 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.
  • SeeLookS SeeLook

    Simply add Qt::uniqueConnection as the last argument of connect command.

    O Offline
    O Offline
    opengpu2
    wrote on last edited by
    #3

    @SeeLook what should i do if i set the last argument Qt::QueuedConnection...

    J 1 Reply Last reply
    0
    • SeeLookS Offline
      SeeLookS Offline
      SeeLook
      wrote on last edited by
      #4
      This post is deleted!
      1 Reply Last reply
      0
      • SeeLookS Offline
        SeeLookS Offline
        SeeLook
        wrote on last edited by
        #5

        @opengpu2 Do You have some reason for that?
        Here is doc of connection types:
        http://doc.qt.io/qt-5.5/qt.html#ConnectionType-enum

        O 1 Reply Last reply
        0
        • O opengpu2

          @SeeLook what should i do if i set the last argument Qt::QueuedConnection...

          J Offline
          J Offline
          Jakob
          wrote on last edited by
          #6

          @opengpu2 You can combine options: simply use Qt::QueuedConnection | Qt::UniqueConnection as last argument to the connect call

          O 2 Replies Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #7

            Hi,

            Connect doesn't overwrite anything, it just creates a new connection unless you use Qt:UniqueConnection like our fellows suggested.

            However that's an option that's rarely used, what is your use case ?

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

            O 1 Reply Last reply
            0
            • SeeLookS SeeLook

              @opengpu2 Do You have some reason for that?
              Here is doc of connection types:
              http://doc.qt.io/qt-5.5/qt.html#ConnectionType-enum

              O Offline
              O Offline
              opengpu2
              wrote on last edited by
              #8

              @SeeLook yep, cross thread use QueuedConnection

              1 Reply Last reply
              0
              • J Jakob

                @opengpu2 You can combine options: simply use Qt::QueuedConnection | Qt::UniqueConnection as last argument to the connect call

                O Offline
                O Offline
                opengpu2
                wrote on last edited by
                #9

                @Jakob so if i set Qt::UniqueConnection, that is equal to Qt::QueuedConnection | Qt::UniqueConnection. right?

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  Connect doesn't overwrite anything, it just creates a new connection unless you use Qt:UniqueConnection like our fellows suggested.

                  However that's an option that's rarely used, what is your use case ?

                  O Offline
                  O Offline
                  opengpu2
                  wrote on last edited by
                  #10

                  @SGaist i wonder why Qt allow the same connect to be created multi-times... i wrongly wrote some connect in func except Constructor&Init(). and when that func is called multi-times, then each emit will cause multi-time slot...
                  i think Qt:UniqueConnection is set by default will be more safe.
                  can i write a custom macro to replace all connect and let them use Qt:UniqueConnection

                  1 Reply Last reply
                  0
                  • J Jakob

                    @opengpu2 You can combine options: simply use Qt::QueuedConnection | Qt::UniqueConnection as last argument to the connect call

                    O Offline
                    O Offline
                    opengpu2
                    wrote on last edited by
                    #11

                    @Jakob i directly set the last param as Qt::QueuedConnection | Qt::UniqueConnection, but there is error canno convert from 'int' to 'Qt::ConnectionType'.
                    so i have to write like this? (Qt::ConnectionType)(Qt::QueuedConnection | Qt::UniqueConnection)

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

                      While there are valid use cases, most of the time creating the exact same connection several times is a design/coding error so making UniqueConnection the default would just hide it and thus open the path to hard to debug behavior/bugs.

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

                      O 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        While there are valid use cases, most of the time creating the exact same connection several times is a design/coding error so making UniqueConnection the default would just hide it and thus open the path to hard to debug behavior/bugs.

                        O Offline
                        O Offline
                        opengpu2
                        wrote on last edited by
                        #13

                        @SGaist ok 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