ChrisW67, wysota, thank you very much for your help.
Originally Posted by
wysota
No, it's not. Everything works fine. But it is a sandbox, I can't replace QAbstractItemModel with QStandardItemModel in the real application, it's too expensive.
Originally Posted by
ChrisW67
If setType() changes internal values that are only used in filterAcceptsRows() the invalidateFilter() would be the correct thing to call. I didn't see a related bug in the tracker. Do you have a bug number?
No, I haven't.
Let me describe the situation in more details:
I have an application with QTreeView, which uses chain of QSortFilterProxyModel (3 filters) to display data from the model. But in my code QSortFilterProxyModel::invalidateFilter() behave itself in very strange way: sometimes it misses rows, no matter which filter model calls it... I don't know if it is a bug in my code (3 days of debug already... oh my head) or in the Qt (4.5), but this:
this->invalidateFilter();
this->invalidateFilter();
this->invalidateFilter();
this->invalidateFilter();
To copy to clipboard, switch view to plain text mode
works just great. If the chain contains only 2 filters, then:
this->invalidate();
this->invalidate();
To copy to clipboard, switch view to plain text mode
works fine too. But it crashes when there are 3 filters.
So I was trying to reproduce the problem in sandbox and I succeed with crash.
Originally Posted by
ChrisW67
Storing pointers to things that invalidate() might throw away is just one of a multitude of things that could be going wrong. Running in a debugger should fairly quickly tell you where your program dies. If you still cannot fathom it then it would help if you could show us what you are doing in the setType() and filterAcceptsRows() methods.
That's funny, this code crashes too:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
m1->setSourceModel(new MyTreeModel(NULL));
m2->setSourceModel(m1);
m3->setSourceModel(m2);
ui->treeView->setModel(m3);
ui->treeView->expandAll();
}
void MainWindow::on_pushButton_clicked()
{
m1->invalidate(); // crash
ui->treeView->expandAll();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m1 = new QSortFilterProxyModel(this);
m1->setSourceModel(new MyTreeModel(NULL));
m2 = new QSortFilterProxyModel(this);
m2->setSourceModel(m1);
m3 = new QSortFilterProxyModel(this);
m3->setSourceModel(m2);
ui->treeView->setModel(m3);
ui->treeView->expandAll();
}
void MainWindow::on_pushButton_clicked()
{
m1->invalidate(); // crash
ui->treeView->expandAll();
}
To copy to clipboard, switch view to plain text mode
, but this works fine:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
m1->setSourceModel(new MyTreeModel(NULL));
m2->setSourceModel(m1);
//m3 = new QSortFilterProxyModel(this);
//m3->setSourceModel(m2);
ui->treeView->setModel(/*m3*/m2);
ui->treeView->expandAll();
}
void MainWindow::on_pushButton_clicked()
{
m1->invalidate(); // works!
ui->treeView->expandAll();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m1 = new QSortFilterProxyModel(this);
m1->setSourceModel(new MyTreeModel(NULL));
m2 = new QSortFilterProxyModel(this);
m2->setSourceModel(m1);
//m3 = new QSortFilterProxyModel(this);
//m3->setSourceModel(m2);
ui->treeView->setModel(/*m3*/m2);
ui->treeView->expandAll();
}
void MainWindow::on_pushButton_clicked()
{
m1->invalidate(); // works!
ui->treeView->expandAll();
}
To copy to clipboard, switch view to plain text mode
The stacktrace, MyTreeModel's implementation and the whole sandbox project are attached. Please let me know if there's anything else I can provide.
Bookmarks