Milo Gertjejansen
Milo Gertjejansen

Reputation: 511

QListWidget.takeItem crashes with segfault

I have snippet of code below:

while(ui->listWidget->count() > 0) {
     QListWidgetItem* aItem = ui->listWidget->takeItem(0);
}

in which I need to empty a QListWidget (the listWidget variable above).

Currently it crashes with a segfault if an item is focused inside it.

I assume that is a problem (the focusing part) but I just don't know why.

My end goals are:

  1. If I can clear the widget, is this the best way to do it?
  2. And if it's not, what is? I looked through the docs and couldn't find a clear method. I admit, I may have missed it, but I have spent several days on this problem.

Upvotes: 0

Views: 607

Answers (1)

JKSH
JKSH

Reputation: 2718

QListWidget::clear() exists. You might have missed it because it is a slot, not just a public function.

http://qt-project.org/doc/qt-4.8/qlistwidget.html#clear

Upvotes: 1

Related Questions