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. QML ListView memory performance
Forum Updated to NodeBB v4.3 + New Features

QML ListView memory performance

Scheduled Pinned Locked Moved Solved QML and Qt Quick
listviewdelegatememoryperformance
3 Posts 2 Posters 3.0k Views 3 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.
  • KroMignonK Offline
    KroMignonK Offline
    KroMignon
    wrote on last edited by KroMignon
    #1

    Hi all,
    in my application (Qt 5.4.2 / QtQuick 2.4), I use ListView to display a more or less big list of items (about 2K elements).
    The ListView items are loaded with usage of model and delegate.
    The model is implemented in C++ (based on QAbstractListModel), and works fine.
    I also have implemented a QSortFilterProxyModel to add some filtering/sorting functions.

    In fact, the ListView can only display 5 elements on the screen and I have to scroll to see all the elements.

    In my delegate Component, I have added traces in Component.onCompleted and Component.onDestruction to follow to loading/destruction of each list item.
    I am surprised to see that all the items from my model are first loaded (2134 elements!!!) and then, when the ListView is displayed, the most of the are distroyed (about 2100 elements!!!).

    Then when I move the scrollbar, I can see in debug log then elements are loaded/destroyed according to my position in the list.

    The loading of the full list, followed by the destruction of 90% of those elements is are very time and memory consuming issue.
    Is there a workaround for this?
    Have I missed something in my ListView initialization?
    Here some extract from my QML item

    Item {
        id: root
        property alias model: tourList.model
        property Component tourListDelegate: TourListDelegate {}
        property bool enabledChacheBuffer: true
        ....
        ScrollBar {
            id: scrollBars
           ...
           ListView {
                id: tourList
                cacheBuffer: enabledChacheBuffer ? (height > 0 ? Math.min(height * 4, appSize.height * 1.5) : 0) : 0
                signal newCurrentIndex(int index)
                highlightMoveDuration: 300
                boundsBehavior: Flickable.StopAtBounds
                currentIndex: -1
                clip: false
                delegate: tourListDelegate
    
    
                onCurrentIndexChanged:
                {
                    // When selecting element from list, ensure full element is visible
                    positionViewAtIndex(currentIndex, ListView.Contain)
                }
            }
        }
    }
    

    Regards,

    Fabrice

    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

    1 Reply Last reply
    0
    • jpnurmiJ Offline
      jpnurmiJ Offline
      jpnurmi
      wrote on last edited by
      #2

      How does the delegate implementation look like? Make sure it has a valid height at construction time, or else ListView will end up filling the view with 0-height delegate items.

      KroMignonK 1 Reply Last reply
      1
      • jpnurmiJ jpnurmi

        How does the delegate implementation look like? Make sure it has a valid height at construction time, or else ListView will end up filling the view with 0-height delegate items.

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #3

        @jpnurmi Thank's a lot! That's it :) Now everything works like a charm :)

        You saved my day!

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        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