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

Access Violation in QAbstractItemView::setModel() in Qt6

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 6.8.2
    • Core: Item Models
    • All

    Description

      QAbstractItemView::setModel(QAbstractItemModel *model) may cause undefined behaviour if model=0 is passed into setModel.

      Reason is the following line:

      d->model = (model ? model : QAbstractItemModelPrivate::staticEmptyModel());
      

      This line looks like it makes sure that d->model is non-null but that's not true, as the assignment from QAbstractItemModelPrivate::staticEmptyModel() may assign a null pointer (e.g. in case we are in the midst of a shutdown / destruction of the view's parent).

      Thus all following code needs to check if d->model != 0 to avoid access violations, but some lines later there is:

      QItemSelectionModel *selection_model = new QItemSelectionModel(d->model, this);
      connect(d->model, &QAbstractItemModel::destroyed, selection_model, &QItemSelectionModel::deleteLater);
      

      which fails with a crash.

      Attachments

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

        Activity

          People

            dfaure_kdab David Faure
            frodo Jens
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes