but when I test your new model I have seen all the top levels items rowsCount() is getting called, I am struggling exactly with this behavior only.
The out put I observed is :Qt Code:
{ qDebug() << parent; //little change in debug msg if(!parent.isValid()) return 10; if(parent.isValid() && !parent.parent().isValid()) return 2; // limit to two levels return 0; } int main(int argc, char **argv) { QTreeView v; v.setFixedSize(200, 50); //set height to 50 so that view can accommodate 2 top level elements only Model model; v.setModel(&model); v.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
QModelIndex(-1,-1,0x0,QObject(0x0) )
QModelIndex(-1,-1,0x0,QObject(0x0) )
QModelIndex(-1,-1,0x0,QObject(0x0) )
QModelIndex(0,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
QModelIndex(1,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
QModelIndex(2,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
QModelIndex(3,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
QModelIndex(4,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
QModelIndex(5,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
QModelIndex(6,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
QModelIndex(7,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
QModelIndex(8,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
QModelIndex(9,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
//rowCount() is getting called for all top level items here.
One more thing I have observed is, When i return 10000000(top level items) in rowCount() (in old model you suggested & in new model also), My application got crashed with runtime error (on Windows 8, 64bit application).
And when I return 1000000 row count & when I try to scroll down its hanging like hell, not able to scroll at all.
Bookmarks