Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get a child of rootIndex() in QTreeView ?
Forum Updated to NodeBB v4.3 + New Features

How to get a child of rootIndex() in QTreeView ?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 7.3k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Anticross
    wrote on last edited by
    #1

    I want to get all top level items in my tree view to make a loop. I do next:
    @QModelIndex root(rootIndex());

    int row = 0;
    
    QModelIndex sessionIndex = root.child(row,SessionsTreeModel::eName);
    
    while (sessionIndex.isValid()) {
        sessionIndex = sessionIndex.sibling(row,SessionsTreeModel::eName);
        int id = m_model->data(sessionIndex,Qt::UserRole).toInt();
    
        if (sessionID == id) {
            m_model->removeSession(sessionIndex.row());
            update();
            return;
        }
    
        row++;
    }@
    

    But my sessionIndex always invalid. I find next in Qt Assistant : bq. QModelIndex QModelIndex::child ( int row, int column ) const

    Returns the child of the model index that is stored in the given row and column.

    Note: This function does not work for an invalid model index which is often used as the root index. bq.

    So how can I get child of rootIndex ?

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

      @
      m_model->index(row, column, rootIndex());
      @
      any good?

      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