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.
setCellWidget
( m_nCurrRow, COL_2,
new QComboBox( this ) );
setCellWidget
( m_nCurrRow, COL_3,
new QPushButton( tr
("Edit"),
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 ) );
To copy to clipboard, switch view to plain text mode
My question is, do I need to explicitly remove the non-QTableWidgetItem ojbects to prevent memory leaks or Qt side-effects?
if ( (pWidget = cellWidget( nRow, COL_2 )) != NULL )
delete pWidget;
if ( (pWidget = cellWidget( nRow, COL_3 )) != NULL )
delete pWidget;
QWidget* pWidget;
if ( (pWidget = cellWidget( nRow, COL_2 )) != NULL )
delete pWidget;
if ( (pWidget = cellWidget( nRow, COL_3 )) != NULL )
delete pWidget;
To copy to clipboard, switch view to plain text mode
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.
Bookmarks