PDA

View Full Version : remove item from QListWidget



yushinee
2nd October 2007, 11:45
Hello,
I am trying to display simple string in QListWidget.
I want to limit the size of item of QlistWidget.
It is not possible to remove item. removeItemWidget function does not work.
Any idea?
Thanks

I use following code.

void SQLTest::UpdateList(QString receivedData)
{
ui.debugList->addItem(new QListWidgetItem(receivedData));
ui.debugList->setCurrentItem(item);

qDebug() << ui.debugList.count() ;
if (ui.debugList->count() == 5){
ui.debugList->removeItemWidget(ui.debugList->item(0));
qDebug() << ui.debugList->count();
}
}

wysota
2nd October 2007, 11:59
If you don't have a widget set in the item, then there is nothing to remove. Try this instead:

delete ui.debugList->item(0);

ntp
2nd October 2007, 20:39
The documentation says to remove an item, use takeItem but you are responsible for deleting that item yourself.



QListWidgetItem* item = ui.debugList->takeItem(0);
delete item;

wysota
2nd October 2007, 20:40
Yes, but you don't have to take() it, if you delete it, it is taken out automatically by the destructor.