Important: Please read the Qt Code of Conduct -

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;
            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);
        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?

  • Moderators

    @Kofr You can't emit beginInsertRows and endInsertRows. They are not signals.

Log in to reply