PDA

View Full Version : QAbstractItemModel and QSortFilterProxyModel -> empty lines and crashes :(



DavidXanatos
5th January 2015, 20:16
Hi

I have a CFilesModel: public QAbstractItemModel that is fed to a QSortFilterProxyModel and this is than fed to a QTreeView

so far so good, the problem arises when I start inserting rows, I get unnecessarily many empty rows and also sometimes crashes when i use beginInsertRows
see void CFilesModel::Fill

EDIT: btw, for the root item beginInsertRows works fine it only messes up when don in a child item :/

my workaround is now not to emit row inserting but instead layoutAboutToBeChanged
see void CFilesModel::Sync(QMap<QString, QList<SFileNode*> >& New, QMap<uint64, SFileNode*>& Old)


I spend a whole day playing around with this damn model and I did not found any way to properly make it working with beginInsertRows

the only workaround I came up with mostly by accident was to use layoutAboutToBeChanged but thats happening on the entire model so it will have a much greater CPU usage :(

can anybody please tell me what I'm doing wrong with this model and the beginInsertRows/endInsertRows emits?

here is my model: http://pastebin.com/NycYhSwM

Cheers
David X.

DavidXanatos
8th January 2015, 10:19
no one expirience with this QAbstractItemModel stuff?

anda_skoa
8th January 2015, 12:26
More likely there is no obvious, easy to spot, error and your code snippet is huge but not build and runnable.

Have you run it through the Qt model test framework?
http://qt-project.org/wiki/Model_Test

Cheers,
_