Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-13605

QStandardItemModel::setItem makes the QPersistentModelIndexindex of the row Item invalid.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 4.8.x, 5.6.0 Alpha
    • Fix Version/s: Some future release
    • Component/s: Core: Item Models
    • Labels:
      None
    • Environment:
      windows, linux

      Description

      QStandardItemModel::setItem makes the QPersistentModelIndexindex of the row Item invalid.

      As per the documentation of QPersistentModelIndex, the item should retain the value of the QPersistentModelIndex until the row item is deleted.

      QStandardItemModel *model;
      model = new QStandardItemModel;

      QStandardItem *item = new QStandardItem();
      item->setData(QString("Text 1"), Qt::DisplayRole);
      model->appendRow(item);

      QStandardItem *item2 = new QStandardItem();
      item2->setData(QString("Text 2"), Qt::DisplayRole);
      model->appendRow(item2);

      QStandardItem *item3 = new QStandardItem();
      item3->setData(QString("Text 3"), Qt::DisplayRole);
      model->appendRow(item3);

      QPersistentModelIndex index = model->index(1,0);

      QStandardItem *newItem = new QStandardItem;
      newItem->setData("changed text", Qt::DisplayRole);
      model->setItem(1, newItem);

      //index is now invalid

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              dfaure_kdab David Faure
              Reporter:
              prakashnadar Prakash Nadar
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes