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?
I'd suggest something like this.
main.qml:
BackButton.qml:
This way, you are not relying on an
id
from outside the component. Instead, you pass in the instance you want the BackButton to operate on - this is much less fragile when refactoring in the future.