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

    • Type: Bug
    • Status: Closed
    • Priority: P5: Not important
    • Resolution: Done
    • Affects Version/s: 5.15.0
    • Fix Version/s: 6.0.0 RC
    • Component/s: Core: Item Models
    • Labels:
      None
    • Platform/s:
      All
    • Commits:
      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

            Assignee:
            dfaure_kdab David Faure
            Reporter:
            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