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

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

    XMLWordPrintable

Details

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

    Description

      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();
      }
      

       

      Attachments

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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes