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

Crash when inserting twice the same widget in QAbstractItemView

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.2.1, 5.3.0
    • Widgets: Itemviews
    • None
    • All.

    Description

      Given an overly-simplified code like this:

      QAbstractItemView* some_view = ...;
      QWidget* some_widget = ...;
      QModelIndex some_index = ...;
      some_view->setIndexWidget(some_index, some_widget); // (1)
      some_view->setIndexWidget(some_index, some_widget); // (2)
      

      Then this code will lead to a crash, because the widget inserted in (1) will be unconditionnally deleted when calling (2)... despite the fact it's actually the same widget.

      The following fix is suggested, to be inserted in QAbstractItemView::setIndexWidget(), line 3124 :

      void QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget)
      {
          Q_D(QAbstractItemView);
          if (!d->isIndexValid(index))
              return;
          QWidget* const oldWidget = indexWidget(index);
          if (oldWidget == widget)
            return;
          if (oldWidget) {
              d->persistent.remove(oldWidget);
              d->removeEditor(oldWidget);
              oldWidget->deleteLater();
          }
      

      Basically, just do nothing if inserting again the same widget.

      Attachments

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

        Activity

          People

            richard Richard Moe Gustavsen
            ybailly@vero Yves Bailly
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes