Do I need to call deleteLater() function if QTreeView has widget ownership?
-
Hello,
I am using
QTreeView
andQStandardItemModel
to represent some data on Table. While representing the data I try to show some widget on table using functionvoid QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget)
. It is show correctly.Now main question is that if user try to set the new data on table at that time I am removing all previous data using
bool QAbstractItemModel::removeRow(int row, const QModelIndex &parent = QModelIndex())
.Do I require to call
deleteLater()
function while removing data? Or removing row from model is automatically delete the widget?auto wdg = treeWidget->indexWidget(index); wdg->disconnect(); wdg->deleteLater();
-
@Yash001
When items are removed from a model the view will update to reflect the new state. Widgets you have added viasetIndexWidget()
which are no longer present will be deleted by Qt infrastructure without you needing to delete them or disconnect from signals. -
@Yash001 said in Do I need to call deleteLater() function if QTreeView has widget ownership?:
setIndexWidget
https://doc.qt.io/qt-5/qabstractitemview.html#setIndexWidget says:
Sets the given widget on the item at the given index, passing the ownership of the widget to the viewport.
-
@Yash001
When items are removed from a model the view will update to reflect the new state. Widgets you have added viasetIndexWidget()
which are no longer present will be deleted by Qt infrastructure without you needing to delete them or disconnect from signals.