Unsolved Memory leaks from QTableView + QStandardItemModel
-
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 ? -
@Maciek0
You don't have to worry about the views/widgets. You just refill your model with a new query's results, theQTableView
will see that and will get rid of any existing stuff and update to just show what is in the model now. -
@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 -
@VRonin
Excactly I use setIndexWidget , and memory horrible expand when I add new, the same query result. -
@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 -
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. -
One middle way between efficiency and ease of use is something like this: https://pastebin.com/XrppLZ3m