PDA

View Full Version : item removement bugs to QListWidget



sai
11th August 2009, 10:34
When I am to clear the QListWiget variant listWidget, a rather strange bugs occur.

first of all, I used the clear() method of QListWidget, it failed.
listWidget->clear();

then, I tried the takeItem() way, it failed again.
for (int i = 0; i < listWidget->count(); i++)
{
QListWidgetItem *item = listWidget->takeItem(0);
delete item;
}

after debugging step by step, I found that, the removing process goes well until it comes to the last item case. the QListWidgetItem *item = listWidget->takeItem(0); sentence failed with the accessing bugs.

faldzip
11th August 2009, 11:36
first of all, I used the clear() method of QListWidget, it failed.

listWidget->clear();
and what does it mean 'failed'? Can you explain it? Application crashed? Or maybe there were remaining items to delete?

And this:


then, I tried the takeItem() way, it failed again.


for (int i = 0; i < listWidget->count(); i++)
{
QListWidgetItem *item = listWidget->takeItem(0);
delete item;
}


should fail as count() is changing while taking item so it will remove only half of items.