Accessing TabView elements by id does not work



  • Hi,

    I want to set a model of a view from some java code. In this simplified example just by using a menu action. The code works, but when putting the view into a Tab I cannot access the view anymore.
    It shows the error: ReferenceError: myview is not defined
    (Using Qt5.3.1)

    Can sombody explain why and how to fix this?

    @
    import QtQuick 2.2
    import QtQuick.Controls 1.1
    import QtQuick.Window 2.0

    ApplicationWindow {
    title: qsTr("demo")
    width: 640
    height: 480
    property int rqid: 0

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
    
            MenuItem {
                text: qsTr("test")
                onTriggered: {
                    myview.model = 10;
                }
            }
    
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }
    
    /* this here works */
    /*TableView {
        id: myview
        anchors.fill: parent
        TableViewColumn{ role: "firstname"  ; title: "First Name" ; width: 100 }
        TableViewColumn{ role: "lastname" ; title: "Last Name" ; width: 200 }
    }*/
    
    /* this here does not */
    TabView {
        id: tabview
        anchors.fill: parent
        Tab {
            title: "Contact List"
            TableView {
                id: myview
                TableViewColumn{ role: "firstname"  ; title: "First Name" ; width: 100 }
                TableViewColumn{ role: "lastname" ; title: "Last Name" ; width: 200 }
            }
        }
    }
    

    }
    @



  • I found a workaround by giving the tab an id and use
    @tabContacts.children[0].model = x.results;@

    Nevertheless it would be nice that ids work also for tab children.


Log in to reply
 

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