Scope of the "id:" with the TabView Control in Qt Quick?
-
Hi!
I have the following simple QML example:
@import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.0ApplicationWindow {
title: qsTr("Hello World")
width: 640
height: 480Button { text: qsTr("Test") anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter onClicked: { tab1.children[0].text = "Hello!" // WORKS !!! txt1.text = "Hi!" // DOESN'T WORK !!! } } TabView { id: tv1 Tab { id: tab1 TextField { id: txt1 text: "Xxx" } } Tab { id: tab2 } }
}
@When I click the button, I want to change the text of the text field control placed on the first tab. The text field control has the id: txt1, but the line
@txt1.text = "Hi!"@
doesn't work and produces the error message:
...Test2.qml:18: ReferenceError: txt1 is not defined
On the other side, the line:
@tab1.children[0].text = "Hello!" @
works as expected which means that the control tree is correct. However this method is less convenient.
Why is the more conveninet id-based method not working in this case?
Best regards,
Draghi