UI: Do not delete via takeItem in ClearListItems
Apparently some raw lingering pointers to the item widgets may be present inside of the QListView if you delete the item widgets directly, and the only way to ensure those pointers are properly cleared is to call ->clear() on the list widget instead of deleting each item individually. We were deleting each item individually because we thought that ->deleteLater might be also be called on other data within, but after some testing, that turned out to not be the case, so it's safe to call ->clear() on the list widget. As a note, deleting item widgets directly is dangerous due to the potential for lingering raw internal pointers, and our case is unique where we can get away with it; do not delete list item widgets directly unless you intend on calling ->clear() or ->takeItem on the specific item you do it to after. Again, the reason why we are deleting list widget items manually is due to the fact that Qt will always use ->deleteLater() on them if they are not deleted manually, which puts their deletion on the queue. Only problem is they cannot be removed from the queue once added, so lingering references to sources will persist until the queue processes them, which causes major problems if we need those objects deleted right away.master
parent
44afc71636
commit
815b916b73
|
@ -40,7 +40,5 @@ void ClearListItems(QListWidget *widget)
|
|||
for (int i = 0; i < widget->count(); i++)
|
||||
delete widget->itemWidget(widget->item(i));
|
||||
|
||||
QListWidgetItem *item = nullptr;
|
||||
while ((item = widget->takeItem(0)))
|
||||
delete item;
|
||||
widget->clear();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue