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. Communication between Qml Objects

Communication between Qml Objects

Scheduled Pinned Locked Moved Solved QML and Qt Quick
13 Posts 4 Posters 2.6k 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.
  • Bhushan_SureB Offline
    Bhushan_SureB Offline
    Bhushan_Sure
    wrote on last edited by
    #1

    how to communicate between 2 qml objects, without defining qml object into other one.
    Like

    One.qml
    {
    }
    
    Two.qml
    {
    }
    

    I want to send signal from one.qml to two.qml so that i can perform some actions in two.qml on the basis of some actions in one.qml.

    i dont want to define one.qml in two.qml.
    is there any way ?

    J.HilkJ 1 Reply Last reply
    0
    • Bhushan_SureB Bhushan_Sure

      how to communicate between 2 qml objects, without defining qml object into other one.
      Like

      One.qml
      {
      }
      
      Two.qml
      {
      }
      

      I want to send signal from one.qml to two.qml so that i can perform some actions in two.qml on the basis of some actions in one.qml.

      i dont want to define one.qml in two.qml.
      is there any way ?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @Bhushan_Sure

      if you gives the qml object an Id, you can access them that way

      One.qml
      {
      id: one
      onMySignal: two.callFunction()//for example
      }
      Two.qml
      {
      id:two
      }
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      Bhushan_SureB 1 Reply Last reply
      3
      • ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        @Bhushan_Sure said in Communication between Qml Objects:

        is there any way ?

        Yes.

        One{
        id:o
        }
        Two{
        id:t
        }
        Component.onCompleted : { o.signalName.connect(t.functionName) }
        

        or

        One{
        id:o
        onSignalName : { t.functionNAme()}
        }
        Two{
        id:t
        }
        
        
        1 Reply Last reply
        2
        • J.HilkJ J.Hilk

          hi @Bhushan_Sure

          if you gives the qml object an Id, you can access them that way

          One.qml
          {
          id: one
          onMySignal: two.callFunction()//for example
          }
          Two.qml
          {
          id:two
          }
          
          Bhushan_SureB Offline
          Bhushan_SureB Offline
          Bhushan_Sure
          wrote on last edited by
          #4

          @J.Hilk where do i have to define Mysignal ?

          J.HilkJ 1 Reply Last reply
          0
          • Bhushan_SureB Bhushan_Sure

            @J.Hilk where do i have to define Mysignal ?

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Bhushan_Sure
            inside One.qml

            signal mySignal()
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            Bhushan_SureB 2 Replies Last reply
            2
            • J.HilkJ J.Hilk

              @Bhushan_Sure
              inside One.qml

              signal mySignal()
              
              Bhushan_SureB Offline
              Bhushan_SureB Offline
              Bhushan_Sure
              wrote on last edited by
              #6

              @J.Hilk @LeLev Ok i will try both the way.

              1 Reply Last reply
              0
              • YunusY Offline
                YunusY Offline
                Yunus
                wrote on last edited by
                #7

                @Bhushan_Sure I also use this method:
                Let say you wanna open other window when clicked:

                onClicked{
                var component = Qt.createComponent("two.qml")
                var window = component.createObject('oneqml mainscope id')
                window.show()
                }

                1 Reply Last reply
                1
                • J.HilkJ J.Hilk

                  @Bhushan_Sure
                  inside One.qml

                  signal mySignal()
                  
                  Bhushan_SureB Offline
                  Bhushan_SureB Offline
                  Bhushan_Sure
                  wrote on last edited by Bhushan_Sure
                  #8

                  @J.Hilk
                  @LeLev
                  @Yunus

                  oneqml.qml

                  Rectangle{
                      id:one
                      height: 400
                      width: 400
                      color: "red"
                      signal mysignal
                  
                      MouseArea {
                          anchors.fill: parent
                          onClicked: {
                              mysignal()
                          }
                      }
                      onMysignal:{
                       two.bhushan()
                      }
                  }
                  

                  twoqml.qml

                  Rectangle
                  {
                      id:two
                      height: 400
                      width: 400
                      color: "yellow"
                  
                      function bhushan()
                      {
                          console.log("Bhushan")
                      }
                  }
                  

                  error is two is not defined
                  What i have done wrong ?

                  J.HilkJ 1 Reply Last reply
                  0
                  • Bhushan_SureB Bhushan_Sure

                    @J.Hilk
                    @LeLev
                    @Yunus

                    oneqml.qml

                    Rectangle{
                        id:one
                        height: 400
                        width: 400
                        color: "red"
                        signal mysignal
                    
                        MouseArea {
                            anchors.fill: parent
                            onClicked: {
                                mysignal()
                            }
                        }
                        onMysignal:{
                         two.bhushan()
                        }
                    }
                    

                    twoqml.qml

                    Rectangle
                    {
                        id:two
                        height: 400
                        width: 400
                        color: "yellow"
                    
                        function bhushan()
                        {
                            console.log("Bhushan")
                        }
                    }
                    

                    error is two is not defined
                    What i have done wrong ?

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #9

                    @Bhushan_Sure said in Communication between Qml Objects:

                    onMysignal

                    the reaction to mySignal needs to be inside the parent - where you instantiate One.qml object


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    Bhushan_SureB 1 Reply Last reply
                    3
                    • J.HilkJ J.Hilk

                      @Bhushan_Sure said in Communication between Qml Objects:

                      onMysignal

                      the reaction to mySignal needs to be inside the parent - where you instantiate One.qml object

                      Bhushan_SureB Offline
                      Bhushan_SureB Offline
                      Bhushan_Sure
                      wrote on last edited by
                      #10

                      @J.Hilk
                      @LeLev
                      @Yunus

                      That worked !!
                      But i don't want to instantiate one.qml into two.qml because
                      whatever there in one.qml that will come in two.qml.

                      Like one rectangle come into two.qml ! you got ?

                      ODБOïO 1 Reply Last reply
                      0
                      • Bhushan_SureB Bhushan_Sure

                        @J.Hilk
                        @LeLev
                        @Yunus

                        That worked !!
                        But i don't want to instantiate one.qml into two.qml because
                        whatever there in one.qml that will come in two.qml.

                        Like one rectangle come into two.qml ! you got ?

                        ODБOïO Offline
                        ODБOïO Offline
                        ODБOï
                        wrote on last edited by
                        #11

                        @Bhushan_Sure said in Communication between Qml Objects:

                        But i don't want to instantiate one.qml into two.qml because

                        you don't have to .. see my first compment

                        //main.qml

                        ...
                        One{
                        id:o
                        onSignalName : { t.functionNAme()}
                        }
                        Two{
                        id:t
                        }
                        ...
                        
                        1 Reply Last reply
                        1
                        • YunusY Offline
                          YunusY Offline
                          Yunus
                          wrote on last edited by Yunus
                          #12

                          @Bhushan_Sure Okey you only need that function do this exactly:(Two 's 't' should be upper case be careful. You also needto recreate your two.qml file as Two.qml

                          //oneqml

                          //up the mousearea
                          Two{
                          id:caller
                          }

                          onClicked{
                          caller.bhushan()
                          }

                          Bhushan_SureB 1 Reply Last reply
                          0
                          • YunusY Yunus

                            @Bhushan_Sure Okey you only need that function do this exactly:(Two 's 't' should be upper case be careful. You also needto recreate your two.qml file as Two.qml

                            //oneqml

                            //up the mousearea
                            Two{
                            id:caller
                            }

                            onClicked{
                            caller.bhushan()
                            }

                            Bhushan_SureB Offline
                            Bhushan_SureB Offline
                            Bhushan_Sure
                            wrote on last edited by
                            #13

                            @Yunus @J-Hilk @LeLev It solved my problem, 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