Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Scope of the "id:" with the TabView Control in Qt Quick?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Draghi
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    1
    • S Offline
      S Offline
      shkryab
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved