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

[Regression] QSortFilterProxyModel::setSourceModel() fails to set a new source model

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Duplicate
    • Affects Version/s: 5.11.0
    • Fix Version/s: 5.11.1
    • Component/s: Widgets: Itemviews
    • Labels:
      None
    • Commits:
      e15fc26e9fdbff141890a3e2e8dc4ef935d022a0

      Description

      The latest change in QSortFilterProxyModel::setSourceModel() caused a regression bug which breaks QSortFilterProxyModel.

      The offending commmit: http://code.qt.io/cgit/qt/qtbase.git/patch/?id=1c0fcbc887459d8963088309e83303eb1a7d2db0

      The "destroyed()" signal of the old model is never disconnected. So after you set a new model and delete the old one, QSortFilterProxyModel:: is reset by the destroyed() signal emitted by the old model and the proxy model is broken.

      The root cause is you called `_q_sourceModelDestroyed()` manually before calling base class `QAbstractProxyModel::setSourceModel()`, which resets d->model to the static empty model object. So in `QAbstractProxyModel::setSourceModel()`, the following line stop working since it disconnects from the static empty model instead of from the old model object. So the old model is never disconnected.

      disconnect(d->model, SIGNAL(destroyed()), this, SLOT(_q_sourceModelDestroyed()));
      

      You can reproduce the bug easily with the test case I attached.

      #include <QSortFilterProxyModel>
      #include <QStandardItemModel>
      #include <assert.h>
      
      int main(int argc, char** argv) {
          auto proxyModel = new QSortFilterProxyModel();
          auto model1 = new QStandardItemModel();
          auto model2 = new QStandardItemModel();
          proxyModel->setSourceModel(model1);
          proxyModel->setSourceModel(model2);
          delete model1;
          assert(proxyModel->sourceModel() == model2);   // the result becomes null while it should be model2
          return 0;
      }
      
      

      proxymodel_bug.cpp

       

      Related discussions in LXQt community: https://github.com/lxqt/libfm-qt/pull/197

       

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              chehrlic Christian Ehrlicher
              Reporter:
              pcman Hong Jen Yee
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes