Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Assert in QSortfilterproxymodel
Forum Updated to NodeBB v4.3 + New Features

Assert in QSortfilterproxymodel

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 764 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by Dariusz
    #1

    Hey

    I'm hitting walls left and right here, maybe some1 would have a hint.

    A simple standalone tests work but its when I mix it all in a weird way that it breaks.

    I have

    1. QTreeView
    2. QSortFilterProxyModel

    and I either have

    1. KDescendantsProxyModel > https://api.kde.org/frameworks/kitemmodels/html/classKDescendantsProxyModel.html
    2. QIdentityModel
      3 . QAbstractModel

    or:

    1. QIdentityModel
      2 . QAbstractModel

    I jump between different models, but the crash I have happens the moment I add an item to my tree and call endInsertRows();

    ASSERT: "source_to_proxy.size() > end" in file C:\Users\qt\work\qt\qtbase\src\corelib\itemmodels\qsortfilterproxymodel.cpp, line 1548

    Qt 6.5

    JonBJ 1 Reply Last reply
    0
    • D Offline
      D Offline
      Dariusz
      wrote on last edited by
      #5

      Ive hit the same problem again while building new system.

      The solution is...
      beginInsertColumns(QModelIndex(), 0, labels.size() - 1);
      endInsertColumns();

      1 Reply Last reply
      0
      • D Dariusz

        Hey

        I'm hitting walls left and right here, maybe some1 would have a hint.

        A simple standalone tests work but its when I mix it all in a weird way that it breaks.

        I have

        1. QTreeView
        2. QSortFilterProxyModel

        and I either have

        1. KDescendantsProxyModel > https://api.kde.org/frameworks/kitemmodels/html/classKDescendantsProxyModel.html
        2. QIdentityModel
          3 . QAbstractModel

        or:

        1. QIdentityModel
          2 . QAbstractModel

        I jump between different models, but the crash I have happens the moment I add an item to my tree and call endInsertRows();

        ASSERT: "source_to_proxy.size() > end" in file C:\Users\qt\work\qt\qtbase\src\corelib\itemmodels\qsortfilterproxymodel.cpp, line 1548

        Qt 6.5

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @Dariusz
        Don't involve some other KDescendantsProxyModel if it's not necessary to reproduce the problem. Show a minimal example using just your "1. QIdentityModel 2 . QAbstractModel" case. Look at which model you are calling beginInsertRows() on and what parameters you are passing to it. Also since your base is QAbstractModel (Item? Table?) that means you have implemented your own model with insertions etc., we cannot possibly know if your code is correct.

        There is a model tester class at https://doc.qt.io/qt-6/qabstractitemmodeltester.html, have you tested your implementation through that?

        ASSERT: "source_to_proxy.size() > end" in file C:\Users\qt\work\qt\qtbase\src\corelib\itemmodels\qsortfilterproxymodel.cpp, line 1548

        Line #1548 without knowing what version of Qt you are using is not great. In https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/itemmodels/qsortfilterproxymodel.cpp?h=dev there is a line #1550 with that ASSERT. It is inside

        void QSortFilterProxyModelPrivate::_q_sourceHeaderDataChanged(Qt::Orientation orientation, int start, int end)
        

        Note that it is for sourceHeader, may be a clue there. It is reporting that it expects the number of rows/columns in the QSortFilterProxyModel' to be greater than the end number passed in, but it is not, i.e. there are too few rows/columns in the proxy for the given end.

        D 1 Reply Last reply
        1
        • JonBJ JonB

          @Dariusz
          Don't involve some other KDescendantsProxyModel if it's not necessary to reproduce the problem. Show a minimal example using just your "1. QIdentityModel 2 . QAbstractModel" case. Look at which model you are calling beginInsertRows() on and what parameters you are passing to it. Also since your base is QAbstractModel (Item? Table?) that means you have implemented your own model with insertions etc., we cannot possibly know if your code is correct.

          There is a model tester class at https://doc.qt.io/qt-6/qabstractitemmodeltester.html, have you tested your implementation through that?

          ASSERT: "source_to_proxy.size() > end" in file C:\Users\qt\work\qt\qtbase\src\corelib\itemmodels\qsortfilterproxymodel.cpp, line 1548

          Line #1548 without knowing what version of Qt you are using is not great. In https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/itemmodels/qsortfilterproxymodel.cpp?h=dev there is a line #1550 with that ASSERT. It is inside

          void QSortFilterProxyModelPrivate::_q_sourceHeaderDataChanged(Qt::Orientation orientation, int start, int end)
          

          Note that it is for sourceHeader, may be a clue there. It is reporting that it expects the number of rows/columns in the QSortFilterProxyModel' to be greater than the end number passed in, but it is not, i.e. there are too few rows/columns in the proxy for the given end.

          D Offline
          D Offline
          Dariusz
          wrote on last edited by
          #3

          Hello @JonB
          Thanks for ping!

          You are right. It was the header, I changed its count, but the way I did it I never notified model of that change which didn't notify submodels.

          Added dataChanged callback on col change. Sadly still breaks.
          I know if I change QSortFIlter key to filter for new stuff, it somehow "Updates" all and then it works. Diggin in to see what I broke where.

          I never knew of QAbstractItemModelTester so will dig in to it, thank you!!! Neato ^^

          D 1 Reply Last reply
          0
          • D Dariusz

            Hello @JonB
            Thanks for ping!

            You are right. It was the header, I changed its count, but the way I did it I never notified model of that change which didn't notify submodels.

            Added dataChanged callback on col change. Sadly still breaks.
            I know if I change QSortFIlter key to filter for new stuff, it somehow "Updates" all and then it works. Diggin in to see what I broke where.

            I never knew of QAbstractItemModelTester so will dig in to it, thank you!!! Neato ^^

            D Offline
            D Offline
            Dariusz
            wrote on last edited by Dariusz
            #4

            @JonB I cant get any QAbstractItemModelTester to spit out any errors... do I need to do anything fancy? :/

            int main(int argc, char *argv[]) {
                auto app = QApplication(argc, argv);
                qSetMessagePattern("[%{time hh:mm:ss.zzz} %{type} %{message}");
                QLoggingCategory::setFilterRules("qt.modeltest=true");
                //QLoggingCategory::setFilterRules("qt.modeltest*=true");
                //QLoggingCategory::setFilterRules("*=true");
            
                qInfo() << "\nTESTING = " << QFileInfo(argv[0]).baseName() << "\t---\t" << argv[0];
            
            
                auto model = ic::gt::icGenericTreeModelGenerator().createTreeModelProxy("0", "0", 0, 0, 0);
            
            
                model->setHeaderText({"Column 1", "Column 2"});
            
                for (int i = 0; i < 10; ++i) {
                    QList<ic::gt::icGenericTreeItem *> items;
                    items.append(new ic::gt::icGenericTreeItem(QString("Item %1").arg(i)));
                    items.append(new ic::gt::icGenericTreeItem(QString("Item %1").arg(i + 10)));
                    model->appendToRoot(items);
                }
            
                // Create a QAbstractItemModelTester instance for your custom model
                auto tester = new QAbstractItemModelTester(model, QAbstractItemModelTester::FailureReportingMode::Fatal);
                // Use the model with a view, for example, a QTreeView
                QTreeView treeView;
                treeView.setModel(model);
                treeView.show();
            
                auto x = app.exec();
                qInfo() << "\nEND TESTING = " << QFileInfo(argv[0]).baseName() << "\t---\t" << argv[0];
                return 0;
            }
            

            https://www.youtube.com/watch?v=Tm1nNyM6Upk&ab_channel=KDAB

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Dariusz
              wrote on last edited by
              #5

              Ive hit the same problem again while building new system.

              The solution is...
              beginInsertColumns(QModelIndex(), 0, labels.size() - 1);
              endInsertColumns();

              1 Reply Last reply
              0
              • D Dariusz has marked this topic as solved on

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved