Proper way to remove items from a QListWidget[Solved]
-
No, your usage is still wrong.
You should always remove the second item, until there is no second item any more, which mean you have only one item now!
or you should remove your item from the last to the second item.
-
To add to 1+1=2, your list size still changes, so your counter is going to grow past the size of your list
-
It's explained in the "documentation":http://qt-project.org/doc/qt-4.8/qlistwidget.html#takeItem
-
If you call takeItem you still need to call delete on it, a better way is to just loop over the items and call delete on them without calling takeItem, it works ok because the dtor will remove itself from the ListWidget during destruction.
-
Rather
@
while (!mListWidget.isEmpty()) {
QListWidgetItem *item ' mListWidget->takeItem();
delete item;
}
@