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
QtWS25 Last Chance

QML ListView memory performance

Scheduled Pinned Locked Moved Solved QML and Qt Quick
listviewdelegatememoryperformance
3 Posts 2 Posters 3.0k 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.
  • K Offline
    K Offline
    KroMignon
    wrote on 28 Jun 2016, 12:55 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
    • J Offline
      J Offline
      jpnurmi
      wrote on 28 Jun 2016, 15:18 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.

      K 1 Reply Last reply 29 Jun 2016, 09:58
      1
      • J jpnurmi
        28 Jun 2016, 15:18

        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.

        K Offline
        K Offline
        KroMignon
        wrote on 29 Jun 2016, 09:58 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

        2/3

        28 Jun 2016, 15:18

        • Login

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