Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    TreeView Shows my data not correctly. What is wrong?

    QML and Qt Quick
    2
    2
    377
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      Kofr last edited by

      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?

      p3c0 1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators @Kofr last edited by

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

        157

        1 Reply Last reply Reply Quote 0
        • First post
          Last post