PDA

View Full Version : Problem with simple Model-View in Qt4.3



ccf_h
17th June 2007, 17:01
The code below (a very simple QTableView example) works fine under Qt4.2.3 but it does not work with Qt4.3.
No idea why. Any help is greatly appreciated.
Thanks
Chris

marcel
17th June 2007, 18:03
The problem is that you did not call beginInsertRows/endInsertRows.
You must call them before/after setModelData, in populate();

Be careful with the parameters for beginInsertRows.


Regards

marcel
17th June 2007, 18:49
Actually, the problem is somewhere else. Forget what I said before.
The docs say:


Resets the model to its original state in any attached views. When a model is reset it means that any previous data reported from the model is now invalid and has to be queried for again.
When a model radically changes its data it can sometimes be easier to just call this function rather than emit dataChanged (http://www.qtcentre.org/forum/qabstractitemmodel.html#dataChanged)() to inform other components when the underlying data source, or its structure, has changed.


You were clearing the data and also reset the model before recreating the back store. This happens in function TableModel: populate.

The error was that when you called reset on the model, it tried to reinitialize with new data ( header views, etc ). But there was no new data, because it was created after you reset the model.

The solution is to call reset just after setModelData(), in populate.
This way the model will have an update source available.

Regards

ccf_h
17th June 2007, 18:57
Great, that worked!!! Thanks a lot. :-)
I still wonder why it worked under Qt4.2 and earlier. They seem to have changed a lot internally.