Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Saving memory by freeing off-screen QListView items?

    General and Desktop
    sql qsqltablemodel model qlistview listview
    4
    10
    489
    Loading More Posts
    • 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
      tague last edited by

      This post is deleted!
      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        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 has to stay free or it will die.

        T 1 Reply Last reply Reply Quote 2
        • T
          tague @Christian Ehrlicher last edited by

          @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 Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion last edited by

            @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 has to stay free or it will die.

            T D 2 Replies Last reply Reply Quote 0
            • T
              tague @Christian Ehrlicher last edited by

              @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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 1
                • T
                  tague @SGaist last edited by

                  @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 Reply Quote 0
                  • Christian Ehrlicher
                    Christian Ehrlicher Lifetime Qt Champion last edited by

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

                    Qt has to stay free or it will die.

                    T 1 Reply Last reply Reply Quote 0
                    • T
                      tague @Christian Ehrlicher last edited by

                      @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 Reply Quote 0
                      • D
                        Davide Guimaraes @Christian Ehrlicher last edited by

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post