PDA

View Full Version : Does clear()/clearContents() delete items?



vycke
31st July 2008, 14:24
I know I'm probably going to feel stupid, but after searching the docs & the forums, I couldn't find an answer to this (and don't have the .cpp files for Qt with the company install)...

When you do a clear() or clearContents() on a QTableWidget (or QTreeWidget), does it delete the QTableWidgetItems in the table? (I sort of assume that widgets in the table might not be deleted, but I'm thinking about the fairly simple implementation.) Currently, I iterate through the rows/columns, take the item & delete it -- but if I can cut down on this "duplicative effort" I could probably get things finished sooner (and still no memory leaks :) )

Thanks all,
Vycke

aamer4yu
31st July 2008, 17:49
QTreeWidget::clear() does delete the items too. I had tested it once. And may be QTableWidget also does the same.

Anyways u can easily verify it. Just subclass the QTreeWidgetItem and QTableWidgetItem, and put a breakpoint in the destructor. Call the clear or clearContents and see if the breakpoint is reached :)