How to call function from parent QML (feedback) ?
-
wrote on 9 Aug 2019, 06:44 last edited by r3d9u11 8 Sept 2019, 06:49
Hi. I have two different QMLs main.qml and Child.qml.
main.qml contains some objects/functions which I want to call from Child.qml.
For example:main.qml:
Window { .... Child { id: myChildQml width: ... height: ... ... fnStart: function () { myTimer.start(); } } ... Timer { id: myTimer interval: 30 repeat: true running: false triggeredOnStart: true onTriggered: { ... } } }
Child.qml:
Rectangle { id: root color: "#a1b2c3" opacity: 0.8 anchors.fill: parent property variant fnStart; Button { id: button x: 19 y: 21 width: 118 height: 57 text: qsTr("Start") } Connections { target: button onClicked: { root.fnStart; } } }
I tried to pass timer.start via custom property fnStart, but it doesn't work.
(sorry if this theme is duplicated, but I didn't find any solution, yet)
Is it possible to realize something like that?
Any ideas?Thanks!
-
Hi. I have two different QMLs main.qml and Child.qml.
main.qml contains some objects/functions which I want to call from Child.qml.
For example:main.qml:
Window { .... Child { id: myChildQml width: ... height: ... ... fnStart: function () { myTimer.start(); } } ... Timer { id: myTimer interval: 30 repeat: true running: false triggeredOnStart: true onTriggered: { ... } } }
Child.qml:
Rectangle { id: root color: "#a1b2c3" opacity: 0.8 anchors.fill: parent property variant fnStart; Button { id: button x: 19 y: 21 width: 118 height: 57 text: qsTr("Start") } Connections { target: button onClicked: { root.fnStart; } } }
I tried to pass timer.start via custom property fnStart, but it doesn't work.
(sorry if this theme is duplicated, but I didn't find any solution, yet)
Is it possible to realize something like that?
Any ideas?Thanks!
wrote on 9 Aug 2019, 06:49 last edited by Pradeep P N 8 Sept 2019, 06:54Please refer Signal and Handler Event System.
- Child.qml
Rectangle { id: root color: "#a1b2c3" opacity: 0.8 anchors.fill: parent signal startFunction() Button { id: button x: 19 y: 21 width: 118 height: 57 text: qsTr("Start") onClicked: { root.startFunction(); } } }
- main.qml
Child { id: myChildQml width: ... height: ... ... onSrartFunction: { // Please start the timer here. } }
All the best.
-
wrote on 9 Aug 2019, 07:07 last edited by
Many thanks for useful link to a conception and code example, it works!
-
wrote on 9 Aug 2019, 09:55 last edited by
Cool :)
All the best.
1/4