Hello,

I use Qt4.3.1 Open Source edition for Windows 32 bits (under Windows XP Pro SP2).

My application has a small interface based upon a QTreeWidget (named "tree") that displays many QTreeWidgetItem *.
When the user clic an item, the signal itemSelectionChanged() is emited. I've got a SLOT linked to this signal, so that I can analyse the item that has been clicked.
So consider the following code as my SLOT block :




With the following code : no problem.
The QTreeWidget is correctly cleared.
Qt Code:
  1. {
  2. tree->clear();
  3. }
To copy to clipboard, switch view to plain text mode 
Quote Originally Posted by Qt Assistant
void QTreeWidget::clear () [slot]
Clears the tree widget by removing all of its items and selections.
Note: Since each item is removed from the tree widget before being deleted, the return value of QTreeWidgetItem::treeWidget() will be invalid when called from an item's destructor.



With the following code : no problem.
The QString contains the informations of the first column of the firts selected item on the QTreeWidget.
Qt Code:
  1. {
  2. QString item_content = ((tree->selectedItems()).at(0))->text(0);
  3. }
To copy to clipboard, switch view to plain text mode 

Quote Originally Posted by Qt Assistant
QList<QTreeWidgetItem *> QTreeWidget::selectedItems () const
Returns a list of all selected non-hidden items.





With the following code : problem.
The application crashes, like it generally happens with memory errors...
Qt Code:
  1. {
  2. QString item_content = ((tree->selectedItems()).at(0))->text(0);
  3. tree->clear();
  4. }
To copy to clipboard, switch view to plain text mode 




I don't really understand the problem, and I can't find any solution.
The API concerning QTreeWidget and QTreeWidgetItem manages lots of pointers, like the list returned by selectedItems(). Certainly should I get the selected items instead of pointers to the selected ones... But I can't achieve to do that.

May you help me, please ?