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

QAbstractItemView::setIndexWidget(): potential issue when setting the same Widget on an Item twice

    XMLWordPrintable

Details

    Description

      This is because deleteLater() is invoked before assigning it again.

      An easy fix would be to return and not do anything if the widget passed is already the existing widget at the given index.

      void QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget)
      {
          Q_D(QAbstractItemView);
          if (!d->isIndexValid(index))
              return;
          if (QWidget *oldWidget = indexWidget(index)) {
              d->removeEditor(oldWidget);
              oldWidget->deleteLater();
          }
          if (widget) {
              widget->setParent(viewport());
              d->persistent.insert(widget);
              d->addEditor(index, widget, true);
              widget->show();
              if (!d->delayedPendingLayout)
                  widget->setGeometry(visualRect(index));
              dataChanged(index, index); // update the geometry
          }
      }
      
      

      possible patch:

      --- a/src/gui/itemviews/qabstractitemview.cpp
      +++ b/src/gui/itemviews/qabstractitemview.cpp
      @@ -2831,7 +2831,7 @@ void QAbstractItemView::closePersistentEditor(const QModelIndex &index)
       void QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget)
       {
           Q_D(QAbstractItemView);
      -    if (!d->isIndexValid(index))
      +    if (!d->isIndexValid(index) || widget == indexWidget(index))
               return;
           if (QWidget *oldWidget = indexWidget(index)) {
               d->removeEditor(oldWidget);
      
      

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            ntg Pierre Rossi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes