How delete item and itemWidget correctly from QListWidget

232 Views Asked by At

i dont understand how correctly delete item and itemWidget from QListWidget. I should at first delete itemWidget, then item

lstWgt->removeItemWidget(item);
delete item;

Or i can

auto *pItem = lstWgt->takeItem(2);
delete item;
1

There are 1 best solutions below

0
Superlokkus On BEST ANSWER

As far as I understand the Qt documentation and by my Qt 4&5 experience, both should be correct, however your last delete should be the Pointer you get returned by takeItem so delete pItem instead of delete item in your second snippet.