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

Unexpected order of modelReset() signals

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P3: Somewhat important
    • None
    • 5.12.1
    • Core: Item Models
    • None
    • Linux/X11

    Description

      I just hunted down a crash in one of my classes. I derived a custom filter proxy model from QSortFilterProxyModel. I also wrote a special filter panel widget which is tightly coupled to the QSortFilterProxyModel derivative. A QAbstractTableModel derivative serves as a source model. A QTableView is attached to the QSortFilterProxyModel derivative.
       
      The filter widget connects a OnProxyModelReset() slot to modelReset() signal of the QSortFilterProxyModel while the QSortFilterProxyModel connects a OnSourceModelReset() slot to the modelReset() signal of its source model.
       
      All works fine until the underlying table source model does a reset. Then it happens that the OnProxyModelReset() slot is executed before the OnSourceModelReset() slot. This is fatal since the QSortFilterProxyModel of course must adapt to the reset ahead of the widget.
       
      The following test snippet demonstrates the problem:

      QStandardItemModel* m = new QStandardItemModel();
      QSortFilterProxyModel* f = new QSortFilterProxyModel();
      f->setSourceModel(m);
        
      CHECK_TRUE(connect(m, &QStandardItemModel::modelReset, this, [&](){ qDebug() << "QStandardItemModel::modelReset"; }));
      CHECK_TRUE(connect(f, &QSortFilterProxyModel::modelReset, this, [&](){ qDebug() << "QSortFilterProxyModel::modelReset"; }));
      // Connection order does not matter (different senders!)
        
       m->clear();

       This prints:

      QSortFilterProxyModel::modelReset
      QStandardItemModel::modelReset

      I expected the opposite order.

      I consider this is a bug since the signal emissions need to correlate with the object hierarchy (i.e. data->sourceModel->proxyModel->panel+view).

      Remark: It could be worth checking if other cascaded signals are emitted that way as well.

       

      Attachments

        1. sortfilterproxy_modelreset_fixed.cpp
          0.6 kB
          David Faure
        2. sortfilterproxy_modelreset.cpp
          0.6 kB
          David Faure
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            dfaure_kdab David Faure
            silicomancer Bernhard Lindner
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes