PDA

View Full Version : Rowcount and insertrows differences



tonnot
13th April 2011, 10:04
I'm playing wiht tablemodel to learn how it works.
I have 'return 40;' (deliberately) at model::rowcount reimplemented function.
I insert 80 rows.
Why I see the first 40 well and I see another 40 more empty ?
It is supossed that only 40 rows are visible....
Any idea ? Thanks

mcosta
13th April 2011, 11:47
Have you reimplemented insertRows ???


An insertRows() implementation must call beginInsertRows() before inserting new rows into the data structure, and it must call endInsertRows() immediately afterwards.


From Qt Docs

void QAbstractItemModel::beginInsertRows ( const QModelIndex & parent, int first, int last ) [protected]
Begins a row insertion operation.
When reimplementing insertRows() in a subclass, you must call this function before inserting data into the model's underlying data store.
The parent index corresponds to the parent into which the new rows are inserted; first and last are the row numbers that the new rows will have after they have been inserted.

Note: This function emits the rowsAboutToBeInserted() signal which connected views (or proxies) must handle before the data is inserted. Otherwise, the views may end up in an invalid state.
See also endInsertRows().

tonnot
14th April 2011, 08:56
Yes, I'm going to look it more in deep.
Thanks