Uploaded image for project: 'Qt Extensions'
  1. Qt Extensions
  2. QTEXT-12

[TreeView] Midlevel node collapse results in invalid index request

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 5
    • TreeView
    • None
    • All

    Description

      When you open multiple levels and then try to collapse a node that is more than one level up the last opened node (but not at the top level). You hit this function:

      int QQuickTreeModelAdaptor::lastChildIndex(const QModelIndex &index)
      {
          if (!m_expandedItems.contains(index))
              return itemIndex(index);
      
          QModelIndex parent = index.parent();
          QModelIndex nextSiblingIndex;
          while (parent.isValid()) {
              nextSiblingIndex = parent.sibling(parent.row() + 1, 0);
              if (nextSiblingIndex.isValid())
                  break;
              parent = parent.parent();
          }
      
          int firstIndex = nextSiblingIndex.isValid() ? itemIndex(nextSiblingIndex) : m_items.count();
          return firstIndex - 1;
      }
      

      Specifically this line: `nextSiblingIndex = parent.sibling(parent.row() + 1, 0);` has the possibility to request an invalid index (one that is out of range). Since the model adaptor can just call `rowCount` I don't see immediately what is the reason to request an invalid index here.

      I would like to throw an exception if an invalid index is requested because I assume Qt code will be careful not to do that so I want to catch any bugs in my own code where I might be requesting an invalid index.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            richard Richard Moe Gustavsen
            mmi_puya Puya Daravi
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes