Fix Editable Tree Model example model rowCount and model instance leak

The rowCount method has been fixed to correctly pass the "Common error
test #3: the second column should NOT have the same children".

It also fixes the model being leaked.

Fixes: QTBUG-92178
Pick-to: 5.15
Change-Id: If92973e6f83ea9a2715bd335269f6e50d80f52c6
Reviewed-by: Luca Beldi <v.ronin@yahoo.it>
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
This commit is contained in:
Samuel Gaist 2021-03-27 08:50:18 +01:00
parent 69dcdbc8da
commit e65558c230
2 changed files with 4 additions and 1 deletions

View File

@ -62,7 +62,7 @@ MainWindow::MainWindow(QWidget *parent)
QFile file(":/default.txt");
file.open(QIODevice::ReadOnly);
TreeModel *model = new TreeModel(headers, file.readAll());
TreeModel *model = new TreeModel(headers, file.readAll(), this);
file.close();
view->setModel(model);

View File

@ -212,6 +212,9 @@ bool TreeModel::removeRows(int position, int rows, const QModelIndex &parent)
//! [8]
int TreeModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() > 0)
return 0;
const TreeItem *parentItem = getItem(parent);
return parentItem ? parentItem->childCount() : 0;