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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • 5.15
    • 4.8.x, 5.6.0 Alpha
    • Core: Item Models
    • None
    • windows, linux
    • 4522b17159a29ffd12c4d93be8a6e8e1a05dccd0

      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

        For Gerrit Dashboard: QTBUG-13605
        # Subject Branch Project Status CR V

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes