mclark
22nd January 2008, 19:23
My question involves the removal of QWidgets placed in QTableWidget cells. I have cells that contain text, QComboBox and QPushButton objects which I initialize like this:
// Initialize table cells. Create a item for COL_2 to aid in sorting.
setItem( m_nCurrRow, COL_1, new QTableWidgetItem( "" ) );
setItem( m_nCurrRow, COL_2, new QTableWidgetItem( "" ) );
setCellWidget( m_nCurrRow, COL_2, new QComboBox( this ) );
setCellWidget( m_nCurrRow, COL_3, new QPushButton( tr("Edit"), this ) );
My question is, do I need to explicitly remove the non-QTableWidgetItem ojbects to prevent memory leaks or Qt side-effects?
QWidget* pWidget;
if ( (pWidget = cellWidget( nRow, COL_2 )) != NULL )
delete pWidget;
if ( (pWidget = cellWidget( nRow, COL_3 )) != NULL )
delete pWidget;
This not just an issue for shutdown. The app is able to remove one or more (all) table rows. My concern is that I am doing unnecessary processing that may cause side-effects when Qt is destroying its objects.
// Initialize table cells. Create a item for COL_2 to aid in sorting.
setItem( m_nCurrRow, COL_1, new QTableWidgetItem( "" ) );
setItem( m_nCurrRow, COL_2, new QTableWidgetItem( "" ) );
setCellWidget( m_nCurrRow, COL_2, new QComboBox( this ) );
setCellWidget( m_nCurrRow, COL_3, new QPushButton( tr("Edit"), this ) );
My question is, do I need to explicitly remove the non-QTableWidgetItem ojbects to prevent memory leaks or Qt side-effects?
QWidget* pWidget;
if ( (pWidget = cellWidget( nRow, COL_2 )) != NULL )
delete pWidget;
if ( (pWidget = cellWidget( nRow, COL_3 )) != NULL )
delete pWidget;
This not just an issue for shutdown. The app is able to remove one or more (all) table rows. My concern is that I am doing unnecessary processing that may cause side-effects when Qt is destroying its objects.