Search code examples
qtqmlqt5.7qtquickcontrols2

Access QML StackView from a control


Sorry for probably a stupid question - I'm very new to QML.

One of my StackView's pages:

Page
{
    id : root

    header: ToolBar
    {   
        BackButton
        {
            anchors.left: parent.left
        }
    }
}

BackButton code:

Button
{
    text: "<"
    font.pixelSize: 20
    width: 30
    onClicked: parent.root.StackView.view.pop()
}

I've tried parent.StackView also. No luck. Getting:

TypeError: Cannot call method 'pop' of null

Is there a solution?


Solution

    1. There is some sort of bug in Qt or Visual Studio 2015. Full rebuild is required generally after some modifications made to QML.
    2. root.StackView.view.pop() is the correct one.