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.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,

  • QML code of TabView (Qt/5.1.0/gcc_64/qml/QtQuick/Controls/TabView.qml) looks like all the tabs are added dynamically. I think the problem in this.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.