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. StackLayout with lazy-loading
Forum Updated to NodeBB v4.3 + New Features

StackLayout with lazy-loading

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

    Hello,
    I want using a StackLayout with lazy-loading, that means load a page on first use and them in memory afterwards.

    I tried the following approach:

    StackLayout {
            id: mainView
            anchors.fill: parent
            anchors.leftMargin: drawer.width
            currentIndex: navigationView.currentIndex
    
            function isCurrentIndex(index) {
                return mainView.currentIndex === index;
            }
    
            Repeater {
                id: mainRepeater
                model: navigationModel.count
    
                Item {
                    id: delegateItem
    
                    // for lazy loading
                    property bool loaded: false
    
                    Loader {
                        anchors.fill: parent
    
                        active: {
                            var source = navigationModel.get(index).pageSource;
                            if (source === undefined)
                                return false;
    
                            // TODO: this generates a binding loop warning
                            if (delegateItem.loaded)
                                return true;
    
                            return mainView.isCurrentIndex(index);
                        }
                        source: navigationModel.get(index).pageSource
    
                        //onActiveChanged: console.log(navigationModel.get(index).pageSource + " is " + active)
    
                        onLoaded: {
                            delegateItem.loaded = true;
                        }
                    }
                }
            }
        }
    

    This works quite nice, but I get an error message: QML Loader: Binding loop detected for property "active"

    Any idea why this is happening?

    cheers!
    Tobias

    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