Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Saving memory by freeing off-screen QListView items?
QtWS25 Last Chance

Saving memory by freeing off-screen QListView items?

Scheduled Pinned Locked Moved Solved General and Desktop
sqlqsqltablemodelmodelqlistviewlistview
10 Posts 4 Posters 1.3k 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
    tague
    wrote on last edited by
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      There is nothing like a QListView item. It's all in the model.
      Don't save the images in memory in full resolution but scale them down.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      T 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        There is nothing like a QListView item. It's all in the model.
        Don't save the images in memory in full resolution but scale them down.

        T Offline
        T Offline
        tague
        wrote on last edited by
        #3

        @Christian-Ehrlicher I'm keeping everything heavily scaled down, actually. I guess then it becomes a matter of making my QSqlTableModel free old records.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @tague said in Saving memory by freeing off-screen QListView items?:

          I guess then it becomes a matter of making my QSqlTableModel free old records.

          How much rows do you have? QSqlTableModel can't 'free' any data.
          Do you derive from QSqlTableModel and fetch the image by your own so you can scale it down? Otherwise there will be the big image in memory.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          T D 2 Replies Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @tague said in Saving memory by freeing off-screen QListView items?:

            I guess then it becomes a matter of making my QSqlTableModel free old records.

            How much rows do you have? QSqlTableModel can't 'free' any data.
            Do you derive from QSqlTableModel and fetch the image by your own so you can scale it down? Otherwise there will be the big image in memory.

            T Offline
            T Offline
            tague
            wrote on last edited by
            #5

            @Christian-Ehrlicher said in Saving memory by freeing off-screen QListView items?:

            How much rows do you have? QSqlTableModel can't 'free' any data.
            Do you derive from QSqlTableModel and fetch the image by your own so you can scale it down? Otherwise there will be the big image in memory.

            I don't do that at the moment, but I am working on creating a similar model class that doesn't retain row information, but instead only SELECTs it when data is invoked.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Beware with that, data is called frequently as the model provides lots of information. Beside what @Christian-Ehrlicher already suggested, you might also want to use a windowing mechanism that fetches a fixed amount of row data and then add/remove new rows depending on the scrolling of the view.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              T 1 Reply Last reply
              1
              • SGaistS SGaist

                Hi,

                Beware with that, data is called frequently as the model provides lots of information. Beside what @Christian-Ehrlicher already suggested, you might also want to use a windowing mechanism that fetches a fixed amount of row data and then add/remove new rows depending on the scrolling of the view.

                T Offline
                T Offline
                tague
                wrote on last edited by
                #7

                @SGaist Thanks for the heads up. Is there a way to do that without my model being heavily dependent on my particular QListView? So far, I've made a generic CachingTableModel that uses a QCache to keep the last few hundred items cached, and which has an overridable virtual method that converts a table row into the appropriate QVariant data representation. It's actually been rather efficient (about 100MB of memory used at its peak) and on my device (with an SSD, reading from an SQLite table of around 8,000 entries) reads new entries with no trouble at all.

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Again - what do you save in that model when there are only 'a few hundreds items' in there and you need 100MB?

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  T 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    Again - what do you save in that model when there are only 'a few hundreds items' in there and you need 100MB?

                    T Offline
                    T Offline
                    tague
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher It caches entries that could have fairly high resolution images in them. 100MB consumed is quite reasonable for my particular use case. I've solved my problem my creating a general-purpose list model class which does not retain too many recent items in memory, and then implementing an application-specific subclass that will automatically produce small, low-resolution thumbnails and save them to a separate table to allow for faster loading later on.

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @tague said in Saving memory by freeing off-screen QListView items?:

                      I guess then it becomes a matter of making my QSqlTableModel free old records.

                      How much rows do you have? QSqlTableModel can't 'free' any data.
                      Do you derive from QSqlTableModel and fetch the image by your own so you can scale it down? Otherwise there will be the big image in memory.

                      D Offline
                      D Offline
                      Davide Guimaraes
                      wrote on last edited by
                      #10
                      This post is deleted!
                      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