[Qt-jambi-interest] QAbstractTableModel problems

Gunnar Sletta gunnar at trolltech.com
Mon Aug 11 07:46:12 CEST 2008


Thomas Coopman wrote:
> Hi,
> 
> I'm trying to write a custom QAbstractTableModel but I have some
> problems with inserting data into the model.
> My model will have a fixed number of columns and data items can be
> added one at a time.
> All the items that are present before I start the model get added
> correctly.  New items that get added in the current row are also shown
> correctly but at the moment I have to insert a new row, no more new
> items are shown.
> I've tried before with both beginInsertColumns and beginInsertRows but
> that didn't work.

Hi Thomas,

It seems you did not specify the proper indices to beginInsertRows(). 
The indices are counted from 0, so to insert one new row you need to 
specify:

beginInsertRows(null, rowCount-1, rowCount-1);

In your code you are adding new entries beyond the end of the table 
which is not possible, hence it does nothing.

I've attached a working example. It adds a new row every two seconds so 
you can see how to use beginInsertRows().

best regards,
Gunnar

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ItemModel.java
Url: http://lists.qt.nokia.com/pipermail/qt-jambi-interest/attachments/20080811/09ffae2f/attachment.pl 


More information about the Qt-jambi-interest mailing list