Important: Please read the Qt Code of Conduct -

StackView attached properties not visible in pushed objects

  • I have a StackView which includes

    initialItem: Qt.resolvedUrl("file.qml")

    In the root Item in file.qml, I can do


    But in the root Item of another.qml, a reference to Stack.view gives the error:

    ReferenceError: Stack is not defined

    Shouldn't the StackView's attached properties be visible in any QML file loaded by the StackView?

  • Hmm, have you tried to use parent instead of Stack like:

  • [quote author="dasRicardo" date="1412850595"]parent.view.push[/quote]

    You can't do parent.view.push, but you can do parent.push. But that's not very convenient if you're not in the root Item.

    I've found that the id: of the StackView is visible in its children, so if its id: is stackView, you can do stackView.push() anywhere in the child.

  • I also have been trying to use attached StackView properties in a component is pushed to a StackView without any luck. I am wondered why this is not worked? So currently I use the ugly workaround accessing StackView by id from a component which was pushed to the StackView.

    The following code located inside component pushed to StackView:

        Component.onCompleted: {
            console.log(StackView.index + " is stack index of the item")

    Gives the following error:

    qrc:/content/IdlePage.qml:18: ReferenceError: StackView is not defined

    But the manual states:

    Attached Property Documentation
    [read-only] StackView.index : int
    This attached property holds the stack index of the item it's attached to, or -1 if the item is not in a stack.

    What I am missing?

  • @GSElabs

    "A common error is to assume that attached properties and signal handlers are directly accessible from the children of the object to which these attributes have been attached. This is not the case. The instance of the attaching type is only attached to specific objects, not to the object and all of its children."

Log in to reply