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 and problem with dataChanged
Qt 6.11 is out! See what's new in the release blog

TreeView and problem with dataChanged

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 568 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.
  • C Offline
    C Offline
    Chilli0
    wrote on last edited by Chilli0
    #1

    Hello,
    I implemented a treeview in QML and i have a problem with dataChanged. It does not update the tree at all. I used "layoutChanged" and it works then, but that's kind of overkill as it reads again all data.

    I can see that that after i call dataChanged, the "parent" method is called for the item i want to update. No other methods are called.

    I have a Root structure which contains all the items. Root iself is not shown in the tree. As the item i want to update is in Root, the parent method returns empty QModelIndex. I tried to return Root with index 0 but it did not help.

    The problem is also visible even if Root is not the parent but another item.

    QModelIndex TreeViewModel::parent(const QModelIndex &index) const
    {
        qDebug() << "parent called";
        QModelIndex modelIndex;
    
        if (index.isValid())
        {
            FileData* item = static_cast<FileData*>(index.internalPointer());
            qDebug() << "parent called for: " << item->filename;
            if (item->parent && item->parent != rootItem)
            {
                qDebug() << "parent: " << item->parent->filename << " - " <<item->parent->index;
                modelIndex = createIndex(item->parent->index, 0, item->parent);
            }
        }
    
        return modelIndex;
    }
    
    void TreeViewModel::updateData(FileData *item)
    {
        //emit layoutAboutToBeChanged();
        qDebug() << "updateData called";
        QModelIndex index = createIndex(item->index, 0, item);
        emit dataChanged(index, index, QList<int>({DownloadProgressRole, IsDownloadedRole}));
        //emit layoutChanged();
    }
    

    In the QML file, inside TreeView i put
    rootIndex: manager.modelIndex

    which returns the Root item.

    Any idea what could be wrong?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chilli0
      wrote on last edited by
      #2

      Ok, i found the issue.
      Turned out that in the updateData function the item->index returned wrong index :)

      1 Reply Last reply
      0
      • C Chilli0 has marked this topic as solved on

      • Login

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