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. How to access Swipeview.view attached property in a Loaded object?

How to access Swipeview.view attached property in a Loaded object?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 217 Views 1 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.
  • vikramgV Offline
    vikramgV Offline
    vikramg
    wrote on last edited by vikramg
    #1

    I am trying to load pages into a SwipeView using a Loader. Per the examples given here I would have expected a Loader source defined in a separate QML file to be able to access the SwipeView attached properties. However I get TypeError: Cannot read property 'currentIndex' of null when I try to access SwipeView.view.currentIndex for instance.

       SwipeView {
            id: view
    
            currentIndex: 1
    
            Item {
                id: firstPage
            }
            Item {
                id: secondPage
                Loader {
                    source: "Step1.qml"
                }
            }
            Item {
                id: thirdPage
            }
    }
    

    In Step1.qml:

    Item {
    
            // visual elements here...
    
            Component.onCompleted: {
                console.log("cindex = " + SwipeView.view.currentIndex) // <-- Cannot read property 'currentIndex' of null
            }
    }
    

    Other attached props like SwipeView.index, SwipeView.isCurrentItem etc can be accessed fine. So why is Swipeview.view not valid within the loaded object?

    I am able to workaround by setting the SwipeView as a property of the Loader; then the SwipeView properties can be accessed as desired:

    Loader {
        property SwipeView sv: view
        source: "Step1.qml"   // Now SV props can be accessed via "sv" in Step1.qml
    }
    

    But considering that SwipeView.view is specified in the documentation as an attached property, I thought I should've been able to use that directly?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved