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

QSortFilterProxyModel does not emit dataChanged when calling setSourceModel() after modifying the source model

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P5: Not important P5: Not important
    • 6.0.0 RC
    • 5.15.0
    • Core: Item Models
    • None
    • All
    • 8455bfee76ed3f1bd3bba8bd3688a7afa94ae0bb (qt/qtbase/dev) 4796296ed6d7b05e2ba94e5a8a28c48350a3c492 (qt/qtbase/5.15)

      Attached is the test demo.untitled.zip

      Before the proxy model calls the setsourcemodel, insert rows and columns for the source model, and then the proxy model cann't send the dataChanged signal.

      The attachment codes are as follows:

      #include <QCoreApplication>
      #include <QStandardItemModel>
      #include <QSortFilterProxyModel>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          QStandardItemModel baseModel;
          QSortFilterProxyModel proxyModel;
      
          /************proxyModel can't emit datachanged*************************/
          baseModel.insertRows(0, 1);
          baseModel.insertColumns(0, 1);
          /********************************************************************/
      
          proxyModel.setSourceModel(&baseModel);
      
          /************proxyModel can emit datachanged*************************/
      //    baseModel.insertRows(0, 1);
      //    baseModel.insertColumns(0, 1);
          /********************************************************************/
      
          QObject::connect(&baseModel, &QStandardItemModel::dataChanged, []{
             qDebug()<<"dataChanged emitted for the base model.";
          });
          QObject::connect(&proxyModel, &QSortFilterProxyModel::dataChanged, []{
             qDebug()<<"dataChanged emitted for the proxy model.";
          });
      
          baseModel.setData(baseModel.index(0, 0), QStringLiteral("new data"), Qt::DisplayRole);
      
          return a.exec();
      }
      

       

        For Gerrit Dashboard: QTBUG-87781
        # Subject Branch Project Status CR V

            dfaure_kdab David Faure
            go_to_last lin wang
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes