Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Connections with two targets?
Qt 6.11 is out! See what's new in the release blog

Connections with two targets?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
11 Posts 4 Posters 9.6k Views 3 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.
  • tekojoT Offline
    tekojoT Offline
    tekojo
    wrote on last edited by
    #2

    Hi @SafaAlfulaij

    Yes, just connect the signals and slots one by one as you need.

    There is even a class for doing more complicated connection mappings:
    http://doc.qt.io/qt-5/qsignalmapper.html

    S 1 Reply Last reply
    0
    • tekojoT tekojo

      Hi @SafaAlfulaij

      Yes, just connect the signals and slots one by one as you need.

      There is even a class for doing more complicated connection mappings:
      http://doc.qt.io/qt-5/qsignalmapper.html

      S Offline
      S Offline
      SafaAlfulaij
      wrote on last edited by
      #3

      @tekojo I was talking about QML Connections type :)

      1 Reply Last reply
      0
      • tekojoT Offline
        tekojoT Offline
        tekojo
        wrote on last edited by
        #4

        Ah, sorry I misunderstood.

        But the same answer :)
        Connections can be used to connect multiple signals to one slot
        http://doc.qt.io/qt-5/qml-qtqml-connections.html#details

        S 1 Reply Last reply
        2
        • tekojoT tekojo

          Ah, sorry I misunderstood.

          But the same answer :)
          Connections can be used to connect multiple signals to one slot
          http://doc.qt.io/qt-5/qml-qtqml-connections.html#details

          S Offline
          S Offline
          SafaAlfulaij
          wrote on last edited by
          #5

          @tekojo Sorry, but I couldn't understand how.

          Is it like (This is just an example):

          MouseArea {
              Connections {
                  onClicked, onEntered: foo(parameters)
              }
          }
          

          And Do I use:

          target: button, textInput
          

          I can make two Connections types, but that's not the question.

          p3c0P kshegunovK 2 Replies Last reply
          1
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #6

            AFAIK there is no way to do this in Connections. An alternative is to use the connect method.

            157

            1 Reply Last reply
            1
            • S SafaAlfulaij

              @tekojo Sorry, but I couldn't understand how.

              Is it like (This is just an example):

              MouseArea {
                  Connections {
                      onClicked, onEntered: foo(parameters)
                  }
              }
              

              And Do I use:

              target: button, textInput
              

              I can make two Connections types, but that's not the question.

              p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #7

              @SafaAlfulaij Not exactly a solution but try the following:

              Item {
                  width: 100
                  height: 100
              
                  QtObject {
                      id: sender
                      signal post (var obj, var data)
                  }
              
                  Item {
                      id: a
                      objectName: "ItemA"
                      Component.onCompleted: {
                          sender.post(this, "This is from Item A")
                      }
                  }
              
                  Item {
                      id: b
                      objectName: "ItemB"
                      Component.onCompleted: {
                          sender.post(this, "This is from Item B")
                      }
                  }
              
                  Connections {
                      target: sender
                      onPost: {
                          console.log(obj, data)
                          console.log(obj.objectName)
                      }
                  }
              }
              
              

              In onPost you get access to individual objects.

              157

              1 Reply Last reply
              2
              • S SafaAlfulaij

                @tekojo Sorry, but I couldn't understand how.

                Is it like (This is just an example):

                MouseArea {
                    Connections {
                        onClicked, onEntered: foo(parameters)
                    }
                }
                

                And Do I use:

                target: button, textInput
                

                I can make two Connections types, but that's not the question.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by kshegunov
                #8

                Is the Connections component a singleton or am I missing something again? As far as I can tell it's a regular QObject, so I think this should work:

                MouseArea {
                    // ...
                    Connections {
                        target: button
                        onClicked: foo(parameters)
                    }
                    Connections {
                         target: textInput
                         onEntered: foo(parameters)
                    }
                }
                

                Read and abide by the Qt Code of Conduct

                p3c0P 1 Reply Last reply
                0
                • kshegunovK kshegunov

                  Is the Connections component a singleton or am I missing something again? As far as I can tell it's a regular QObject, so I think this should work:

                  MouseArea {
                      // ...
                      Connections {
                          target: button
                          onClicked: foo(parameters)
                      }
                      Connections {
                           target: textInput
                           onEntered: foo(parameters)
                      }
                  }
                  
                  p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #9

                  @kshegunov that is possible too. But OP is asking for a single Connections objects and which can accept 2 targets.

                  157

                  kshegunovK 1 Reply Last reply
                  0
                  • p3c0P p3c0

                    @kshegunov that is possible too. But OP is asking for a single Connections objects and which can accept 2 targets.

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #10

                    @p3c0
                    Well, that's only marginally less verbose. And since onClicked, onEntered etc. are already slots I don't see how that feature should work in the first place ...

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    0
                    • p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #11

                      @kshegunov Perhaps OP must have thought of comparing c++ feature

                      157

                      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
                      • Unsolved