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. I can't get the signal to work in QML

I can't get the signal to work in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 700 Views
  • 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.
  • W Offline
    W Offline
    w.tkm
    wrote on last edited by w.tkm
    #1

    Hi.
    I want to use signal in QML.
    I did it this way, but I can't do.

    main.qml

    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        MyRect{
            anchors.centerIn: parent
            height: 50
            width: 50
            color: "red"
            border.width: 1
            border.color: "gray"
        }
    
        Connections{
            target: MyRectForm
            function testSig(){
                console.log("get")
            }
        }
    }
    

    MyRectForm.qml

    MyRectForm{
    
        signal testSig
    
        Connections{
            target: rectMouseArea
            function onClicked(){
                console.log("send")
                testSig()
            }
        }
    }
    

    The content of MyRect.ui.qml is a very simple rectangle.
    I get log "send", when I click this rectangle. But I don't get "get".

    I thought it might be possible, so I tried changing "function testSig()" to "function onTestSig()", but I got an error.
    It error string is
    [QML Connections: Detected function "onTestSig" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name.]

    How can I get the signal to work?

    eyllanescE 1 Reply Last reply
    0
    • W w.tkm

      @eyllanesc
      Sorry, It in MyRect.qml

      Rectangle{
          id: systemRect
          property alias rectMouseArea: rectMouseArea
      
          MouseArea{
              id: rectMouseArea
              anchors.fill: parent
          }
      }
      
      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #4

      @w-tkm MyRectForm makes no sense in main.qml, target must have the id of the item that has the signal:

      import QtQuick 2.15
      import QtQuick.Window 2.15
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          MyRect{
              id: myRect
              anchors.centerIn: parent
              height: 50
              width: 50
              color: "red"
              border.width: 1
              border.color: "gray"
          }
      
          Connections{
              target: myRect
              function onTestSig(){
                  console.log("get")
              }
          }
      }
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      W 1 Reply Last reply
      0
      • W w.tkm

        Hi.
        I want to use signal in QML.
        I did it this way, but I can't do.

        main.qml

        Window {
            width: 640
            height: 480
            visible: true
            title: qsTr("Hello World")
        
            MyRect{
                anchors.centerIn: parent
                height: 50
                width: 50
                color: "red"
                border.width: 1
                border.color: "gray"
            }
        
            Connections{
                target: MyRectForm
                function testSig(){
                    console.log("get")
                }
            }
        }
        

        MyRectForm.qml

        MyRectForm{
        
            signal testSig
        
            Connections{
                target: rectMouseArea
                function onClicked(){
                    console.log("send")
                    testSig()
                }
            }
        }
        

        The content of MyRect.ui.qml is a very simple rectangle.
        I get log "send", when I click this rectangle. But I don't get "get".

        I thought it might be possible, so I tried changing "function testSig()" to "function onTestSig()", but I got an error.
        It error string is
        [QML Connections: Detected function "onTestSig" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name.]

        How can I get the signal to work?

        eyllanescE Offline
        eyllanescE Offline
        eyllanesc
        wrote on last edited by eyllanesc
        #2

        @w-tkm what is rectMouseArea? share MyRectForm.ui.qml

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        W 1 Reply Last reply
        0
        • eyllanescE eyllanesc

          @w-tkm what is rectMouseArea? share MyRectForm.ui.qml

          W Offline
          W Offline
          w.tkm
          wrote on last edited by
          #3

          @eyllanesc
          Sorry, It in MyRect.qml

          Rectangle{
              id: systemRect
              property alias rectMouseArea: rectMouseArea
          
              MouseArea{
                  id: rectMouseArea
                  anchors.fill: parent
              }
          }
          
          eyllanescE 1 Reply Last reply
          0
          • W w.tkm

            @eyllanesc
            Sorry, It in MyRect.qml

            Rectangle{
                id: systemRect
                property alias rectMouseArea: rectMouseArea
            
                MouseArea{
                    id: rectMouseArea
                    anchors.fill: parent
                }
            }
            
            eyllanescE Offline
            eyllanescE Offline
            eyllanesc
            wrote on last edited by
            #4

            @w-tkm MyRectForm makes no sense in main.qml, target must have the id of the item that has the signal:

            import QtQuick 2.15
            import QtQuick.Window 2.15
            
            Window {
                width: 640
                height: 480
                visible: true
                title: qsTr("Hello World")
            
                MyRect{
                    id: myRect
                    anchors.centerIn: parent
                    height: 50
                    width: 50
                    color: "red"
                    border.width: 1
                    border.color: "gray"
                }
            
                Connections{
                    target: myRect
                    function onTestSig(){
                        console.log("get")
                    }
                }
            }
            

            If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

            W 1 Reply Last reply
            0
            • eyllanescE eyllanesc

              @w-tkm MyRectForm makes no sense in main.qml, target must have the id of the item that has the signal:

              import QtQuick 2.15
              import QtQuick.Window 2.15
              
              Window {
                  width: 640
                  height: 480
                  visible: true
                  title: qsTr("Hello World")
              
                  MyRect{
                      id: myRect
                      anchors.centerIn: parent
                      height: 50
                      width: 50
                      color: "red"
                      border.width: 1
                      border.color: "gray"
                  }
              
                  Connections{
                      target: myRect
                      function onTestSig(){
                          console.log("get")
                      }
                  }
              }
              
              W Offline
              W Offline
              w.tkm
              wrote on last edited by
              #5

              @eyllanesc
              Thanks,I have one more question.

                  Row{
                          anchors.centerIn: parent
                          Repeater{
                              id: rectSet
                              model: 3
                              MyRect{
                                  width: 50
                                  height: 50
                                  color: "red"
                                  border.width: 1
                                  border.color: "gray"
                              }
                          }
                      }
              

              What should I do if I use a Repeater in this way?

              eyllanescE 1 Reply Last reply
              0
              • W w.tkm

                @eyllanesc
                Thanks,I have one more question.

                    Row{
                            anchors.centerIn: parent
                            Repeater{
                                id: rectSet
                                model: 3
                                MyRect{
                                    width: 50
                                    height: 50
                                    color: "red"
                                    border.width: 1
                                    border.color: "gray"
                                }
                            }
                        }
                

                What should I do if I use a Repeater in this way?

                eyllanescE Offline
                eyllanescE Offline
                eyllanesc
                wrote on last edited by
                #6

                @w-tkm If you have another question then create another post

                If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                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