Assert in QSortfilterproxymodel
-
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
- QTreeView
- QSortFilterProxyModel
and I either have
- KDescendantsProxyModel > https://api.kde.org/frameworks/kitemmodels/html/classKDescendantsProxyModel.html
- QIdentityModel
3 . QAbstractModel
or:
- 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
-
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
- QTreeView
- QSortFilterProxyModel
and I either have
- KDescendantsProxyModel > https://api.kde.org/frameworks/kitemmodels/html/classKDescendantsProxyModel.html
- QIdentityModel
3 . QAbstractModel
or:
- 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
@Dariusz
Don't involve some otherKDescendantsProxyModel
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 callingbeginInsertRows()
on and what parameters you are passing to it. Also since your base isQAbstractModel
(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 insidevoid 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 theQSortFilterProxyModel
' to be greater than theend
number passed in, but it is not, i.e. there are too few rows/columns in the proxy for the givenend
. -
@Dariusz
Don't involve some otherKDescendantsProxyModel
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 callingbeginInsertRows()
on and what parameters you are passing to it. Also since your base isQAbstractModel
(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 insidevoid 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 theQSortFilterProxyModel
' to be greater than theend
number passed in, but it is not, i.e. there are too few rows/columns in the proxy for the givenend
.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 ^^
-
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 ^^
@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; }
-