Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. TreeView Shows my data not correctly. What is wrong?

TreeView Shows my data not correctly. What is wrong?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 503 Views
  • 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 Offline
    K Offline
    Kofr
    wrote on last edited by
    #1

    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?

    p3c0P 1 Reply Last reply
    0
    • K Kofr

      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?

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

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

      157

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved