Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. receive signal from other qml objec(these two object don't have parent-child relation but they have common parent.).

receive signal from other qml objec(these two object don't have parent-child relation but they have common parent.).

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 1.4k 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.
  • P Offline
    P Offline
    PooyaSis
    wrote on last edited by
    #1

    hello,i've been searching and still couldnt find answer. How can i send signal in one qml object and recive it in another object? considering that they dont have parent child relation. but they have common parents.

    raven-worxR 1 Reply Last reply
    0
    • P PooyaSis

      hello,i've been searching and still couldnt find answer. How can i send signal in one qml object and recive it in another object? considering that they dont have parent child relation. but they have common parents.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @PooyaSis
      one possibility:

      Item {
         Item {
           id: child1
          signal mySignal()
        } 
        Item {
           id: child2
          function mySlot() {
             ...
          }
           Component.onComplete: child1.mySignal.connect(child2.mySlot)
        } 
      }
      

      Also you may want to read this

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • P Offline
        P Offline
        PooyaSis
        wrote on last edited by PooyaSis
        #3

        @raven-worx
        thanks
        but what if they are not in same file?
        for example:

        // common parent
        item {
            Child1 {}
            Child2 {}
        }
        
        //Child1.qml
        Item {
            id:child1
            Rectangle {
                id:rec1
            }
        }
        
        //Child2.qml
        Item {
            id:child2
            Rectangle {
                id:rec2
        
                MouseArea {
                    anchors.fill: parent
                    onClicked: { "Some Code to change rec1 color" }
                     }  
               }
        }
        

        how can I change color of rec1 from onClicked in rec2?

        raven-worxR 1 Reply Last reply
        0
        • P PooyaSis

          @raven-worx
          thanks
          but what if they are not in same file?
          for example:

          // common parent
          item {
              Child1 {}
              Child2 {}
          }
          
          //Child1.qml
          Item {
              id:child1
              Rectangle {
                  id:rec1
              }
          }
          
          //Child2.qml
          Item {
              id:child2
              Rectangle {
                  id:rec2
          
                  MouseArea {
                      anchors.fill: parent
                      onClicked: { "Some Code to change rec1 color" }
                       }  
                 }
          }
          

          how can I change color of rec1 from onClicked in rec2?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @PooyaSis said in receive signal from other qml objec(these two object don't have parent-child relation but they have common parent.).:

          how can I change color of rec1 from onClicked in rec2?

          Item {
              Child1 {
                 id: child1
              }
              Child2 {
                 id: child2
              }
          
              Component.onComplete: child1.mySignal.connect(child2.mySlot)
          }
          
          //Child1.qml
          Item {
              id: base
          
             function mySlot() {
                rec1.color = "red"
             }
          
              Rectangle {
                  id:rec1
              }
          }
          
          //Child2.qml
          Item {
              id: base
              signal mySignal()
          
              Rectangle {
                  id:rec2
          
                  MouseArea {
                      anchors.fill: parent
                      onClicked: base.mySignal()
                 }
          }
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          P 1 Reply Last reply
          3
          • raven-worxR raven-worx

            @PooyaSis said in receive signal from other qml objec(these two object don't have parent-child relation but they have common parent.).:

            how can I change color of rec1 from onClicked in rec2?

            Item {
                Child1 {
                   id: child1
                }
                Child2 {
                   id: child2
                }
            
                Component.onComplete: child1.mySignal.connect(child2.mySlot)
            }
            
            //Child1.qml
            Item {
                id: base
            
               function mySlot() {
                  rec1.color = "red"
               }
            
                Rectangle {
                    id:rec1
                }
            }
            
            //Child2.qml
            Item {
                id: base
                signal mySignal()
            
                Rectangle {
                    id:rec2
            
                    MouseArea {
                        anchors.fill: parent
                        onClicked: base.mySignal()
                   }
            }
            
            P Offline
            P Offline
            PooyaSis
            wrote on last edited by
            #5

            @raven-worx thanks for your help. solved.

            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