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. Memory leaks from QTableView + QStandardItemModel

Memory leaks from QTableView + QStandardItemModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 826 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.
  • Maciek0M Offline
    Maciek0M Offline
    Maciek0
    wrote on last edited by
    #1

    Hello.
    I create TableView object with model from QStandardItemModel. Model use QSqlQuery result. In First column in any cell il add button with menu (I add some actions to menu). I want ask howto to menage memory in TableView from this example ? How to clear memory from model and his cells widgets when il load new query data ?

    JonBJ VRoninV 2 Replies Last reply
    0
    • Maciek0M Maciek0

      Hello.
      I create TableView object with model from QStandardItemModel. Model use QSqlQuery result. In First column in any cell il add button with menu (I add some actions to menu). I want ask howto to menage memory in TableView from this example ? How to clear memory from model and his cells widgets when il load new query data ?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Maciek0
      You don't have to worry about the views/widgets. You just refill your model with a new query's results, the QTableView will see that and will get rid of any existing stuff and update to just show what is in the model now.

      1 Reply Last reply
      0
      • Maciek0M Maciek0

        Hello.
        I create TableView object with model from QStandardItemModel. Model use QSqlQuery result. In First column in any cell il add button with menu (I add some actions to menu). I want ask howto to menage memory in TableView from this example ? How to clear memory from model and his cells widgets when il load new query data ?

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        @Maciek0 said in Memory leaks from QTableView + QStandardItemModel:

        il add button with menu

        How? if your answer is setIndexWidget then bin it and subclass a delegate instead

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        Maciek0M 1 Reply Last reply
        1
        • VRoninV VRonin

          @Maciek0 said in Memory leaks from QTableView + QStandardItemModel:

          il add button with menu

          How? if your answer is setIndexWidget then bin it and subclass a delegate instead

          Maciek0M Offline
          Maciek0M Offline
          Maciek0
          wrote on last edited by
          #4

          @VRonin
          Excactly I use setIndexWidget , and memory horrible expand when I add new, the same query result.

          VRoninV 1 Reply Last reply
          0
          • Maciek0M Maciek0

            @VRonin
            Excactly I use setIndexWidget , and memory horrible expand when I add new, the same query result.

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @Maciek0 said in Memory leaks from QTableView + QStandardItemModel:

            and memory horrible expand when I add new

            Indeed! that's why setIndexWidget is evil incarnate.

            What you need to do is subclass QStyledItemDelegate and reimplement its functionalities

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            5
            • qwasder85Q Offline
              qwasder85Q Offline
              qwasder85
              wrote on last edited by
              #6

              It's the classic conundrum of "I want to see a widget in each cell, but I don't want them in the memory". I've been over this issue with my product owners so many times.
              Change your approach or find a compromise, this road will only end in tears.

              Maybe its enough to only show the button in the currently selected row? Write a custom delegate and have it display the button as its editor widget.
              Then make sure that the cell is forced into edit mode when the row is selected.

              1 Reply Last reply
              2
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #7

                One middle way between efficiency and ease of use is something like this: https://pastebin.com/XrppLZ3m

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                3

                • Login

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