Qt tablewidget的removeRow()这个方法,删除行以后,行中的item是否被自动释放了还是需要手动delete掉
这两个方法都已经将内存delete掉。看SRC就知道了。
http://code.woboq.org/kde/qt4/src/gui/itemviews/qtablewidget.cpp.html
bool QTableModel::removeRows(int row, int count, const QModelIndex &)
101{
102 if (count <1|| row <0|| row + count > verticalHeaderItems.count())
103 return false;
104
105 beginRemoveRows(QModelIndex(), row, row + count -1);
106 int i= tableIndex(row,0);
107 int n= count * columnCount();
108 QTableWidgetItem *oldItem=0;
109 for (int j= i; j < n + i; ++j) {
110 oldItem = tableItems.at(j);
111 if (oldItem)
112 oldItem->view =0;
113 delete oldItem;
114 }
115 tableItems.remove(qMax(i,0), n);
116 for (int v= row; v < row + count; ++v) {
117 oldItem = verticalHeaderItems.at(v);
118 if (oldItem)
119 oldItem->view =0;
120 delete oldItem;
121 }
122 verticalHeaderItems.remove(row, count);
123 endRemoveRows();
124 return true;
125}
void QTableModel::clear()
{
for (int j = 0; j < verticalHeaderItems.count(); ++j) {
if (verticalHeaderItems.at(j)) {
verticalHeaderItems.at(j)->view = 0;
delete verticalHeaderItems.at(j);; // <--
verticalHeaderItems[j] = 0;
}
}
for (int k = 0; k < horizontalHeaderItems.count(); ++k) {
if (horizontalHeaderItems.at(k)) {
horizontalHeaderItems.at(k)->view = 0;
delete horizontalHeaderItems.at(k);; // <--
horizontalHeaderItems[k] = 0;
}
}
clearContents();
}