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. StackView attached properties not visible in pushed objects
Forum Updated to NodeBB v4.3 + New Features

StackView attached properties not visible in pushed objects

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 4 Posters 2.5k Views 2 Watching
  • 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.
  • X Offline
    X Offline
    xargs
    wrote on last edited by
    #1

    I have a StackView which includes

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

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

    Stack.view.push(Qt.resolvedUrl("another.qml")).

    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?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dasRicardo
      wrote on last edited by
      #2

      Hmm, have you tried to use parent instead of Stack like:
      @
      parent.view.push(Qt.resolvedUrl(“another.qml”))
      @

      **Sorry for my english :)

      PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xargs
        wrote on last edited by
        #3

        [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.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GSElabs
          wrote on last edited by GSElabs
          #4

          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?

          N 1 Reply Last reply
          0
          • G GSElabs

            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?

            N Offline
            N Offline
            Nifiro
            wrote on last edited by
            #5

            @GSElabs
            https://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html#a-note-about-accessing-attached-properties-and-signal-handlers

            "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."

            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