How to use signal when using a repeater
-
wrote on 13 Sept 2021, 03:19 last edited by
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? -
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?wrote on 13 Sept 2021, 03:25 last edited by@w-tkm Change to:
Connections{ target: rowRect.count > 0 ? rowRect.itemAt(0): null function onTestSig(){ console.log("get") } }
-
@w-tkm Change to:
Connections{ target: rowRect.count > 0 ? rowRect.itemAt(0): null function onTestSig(){ console.log("get") } }
wrote on 13 Sept 2021, 04:11 last edited by@eyllanesc
Thanks!
I do this.
1/3