TreeView Shows my data not correctly. What is wrong?
-
Here is the function of adding a child
bool TreeModel::addChild(const QVariant &data, const QModelIndex &parent) { Task *parentTask; if (!parent.isValid()){ qDebug() << "addChild() - parent is not valid"; parentTask = rootItem; } else parentTask = static_cast<Task*>(parent.internalPointer()); Task *childTask = new Task(data, parentTask); qDebug() << QString::number((int)childTask);/// int childCount = childTask->childCount(); emit beginInsertRows(parent, childCount, childCount); parentTask->appendChild(childTask); emit endInsertRows(); //emit dataChanged(parent, parent); return true; }
In some situations calling this function from QML makes a mess with Indexes in QML. It start show wrong items or invalid items, especially when Parent has tasks with children (2 levels tree).
What is wrong?