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

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

    XMLWordPrintable

Details

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

    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

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

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes