PDA

View Full Version : QTableWidget -- SetItem



QbelcorT
29th July 2009, 03:08
Hi,
I created a QTableWidget to illustrate the available wireless networks. The rowCount will be dynamic depending on number of networks. CellList is just text names I create before entering this loop.
My concern is using the 'new' for the QTableWidgetItem. It is possible this routine to populate the table will be called on a button press to refresh.
How or when should I delete (release) the memory?
Will QTableWidget::clearContents() accomplish this?



for (int i = 0; i < rowCount; i++ )
{
QTableWidgetItem *__essidName = new QTableWidgetItem(CellList[i][1].at(0));
uiWireless->availableNetworksTable->setItem(i,0,__essidName);
QTableWidgetItem *__strengthValue = new QTableWidgetItem(CellList[i][6].at(0));
uiWireless->availableNetworksTable->setItem(i,1,__strengthValue);
}

nish
29th July 2009, 03:19
ya... the clear function will delete the items.. you can always check this by holding a item pointer and then clearcontents.. after that try to use the item.. if you app crashes then the item is deleted :)

aamer4yu
29th July 2009, 05:25
ya... the clear function will delete the items.. you can always check this by holding a item pointer and then clearcontents.. after that try to use the item.. if you app crashes then the item is deleted
Better way would be to subclass QTableWidgetItem and put a break point in destructor and check if the destructor is called when clearContents is called.

nish
29th July 2009, 06:00
Better way would be to subclass QTableWidgetItem and put a break point in destructor and check if the destructor is called when clearContents is called.

too much coding for a simple check.. furthermore i like things to burn in horror...:)