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. How to use signal when using a repeater
Forum Updated to NodeBB v4.3 + New Features

How to use signal when using a repeater

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 328 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 13 Sept 2021, 03:19 last edited by
    #1

    Hi.
    I want to use signal when using a repeater
    I did it this way, but I can't do.

    main.qml

    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        Row{
            anchors.top: parent.top
                Repeater{
                id: rowRect
                model: 3
                MyRect{
                    width: 50
                    height: 50
                    color: "#444343"
                    border.width: 1
                    border.color: "gray"
                }
            }
        }
    
        Connections{
            target: rowRect.itemAt(0)
            function testSig(){
                console.log("get")
            }
        }
    }
    

    MyRectForm.qml

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

    MyRect.qml

    Rectangle{
        id: systemRect
        property alias rectMouseArea: rectMouseArea
    
        MouseArea{
            id: rectMouseArea
            anchors.fill: parent
        }
    }
    

    When I click on the first rectangle, I want the signal to move, but it doesn't.
    How do I do this?

    E 1 Reply Last reply 13 Sept 2021, 03:25
    0
    • W w.tkm
      13 Sept 2021, 03:19

      Hi.
      I want to use signal when using a repeater
      I did it this way, but I can't do.

      main.qml

      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          Row{
              anchors.top: parent.top
                  Repeater{
                  id: rowRect
                  model: 3
                  MyRect{
                      width: 50
                      height: 50
                      color: "#444343"
                      border.width: 1
                      border.color: "gray"
                  }
              }
          }
      
          Connections{
              target: rowRect.itemAt(0)
              function testSig(){
                  console.log("get")
              }
          }
      }
      

      MyRectForm.qml

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

      MyRect.qml

      Rectangle{
          id: systemRect
          property alias rectMouseArea: rectMouseArea
      
          MouseArea{
              id: rectMouseArea
              anchors.fill: parent
          }
      }
      

      When I click on the first rectangle, I want the signal to move, but it doesn't.
      How do I do this?

      E Offline
      E Offline
      eyllanesc
      wrote on 13 Sept 2021, 03:25 last edited by
      #2

      @w-tkm Change to:

      Connections{
          target: rowRect.count > 0 ? rowRect.itemAt(0): null
          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 13 Sept 2021, 04:11
      0
      • E eyllanesc
        13 Sept 2021, 03:25

        @w-tkm Change to:

        Connections{
            target: rowRect.count > 0 ? rowRect.itemAt(0): null
            function onTestSig(){
                console.log("get")
            }
        }
        
        W Offline
        W Offline
        w.tkm
        wrote on 13 Sept 2021, 04:11 last edited by
        #3

        @eyllanesc
        Thanks!
        I do this.

        1 Reply Last reply
        0

        1/3

        13 Sept 2021, 03:19

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved