PDA

View Full Version : QTreeWidget Problems



Ryan Riffle
16th January 2011, 04:12
I'm wanting to unselect the only (1) selected item in my QTreeWidget,
but when I use my code, It returns:

ASSERT failure in QList<T>::at: "index out of range", file /usr/include/qt4/QtCore/qlist.h, line 439

Here is my code:


if(ui->treeWidget->selectedItems().count()>0)
{
QTreeWidgetItem *i = ui->treeWidget->selectedItems().first();
i->setSelected(0);
}


Is there something wrong with my code? It looks right to me...

Added after 1 41 minutes:

It seems to me that there is something wrong with the QTreeWidget. But I'm not sure.

norobro
16th January 2011, 20:44
Your code worked fine for me in a simple test program even with multiple selections.


I'm wanting to unselect the only (1) selected item in my QTreeWidget
If you only allow single selections you could use
ui->treeWidget->selectionModel()->clear();