Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Scope of the "id:" with the TabView Control in Qt Quick?

$
0
0
Hi! I have the following simple QML example: import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Window 2.0   ApplicationWindow {     title: qsTr("Hello World")     width: 640     height: 480         Button {         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

Viewing all articles
Browse latest Browse all 4972

Trending Articles