Skip navigation.
KDE Developer's Journals

Model/View

frederik gladhorn's picture

I always pass on good advice. It is the only thing to do with it. It is never of any use to oneself.
Oscar Wilde

Quite some time ago, Pino gave me a great tip (hm, maybe advice is of use occasionally)...
Use Modeltest from labs.trolltech.com to validate QAbstractItemModels.
It's as simple as including modeltest.cpp in your CMakeLists.txt, add
#include "modeltest.h"
and when constructing the model, hand over the model pointer to a ModelTest instance.
new ModelTest(myQAbstractItemModel, parent);
Then you'll have a hard time starting your app for a while, since ModelTest is somewhat picky (but that's what you wanted, right?).
Once you manage to get past all the ASSERTS checking for correct parenting and the like your model will have been a bit refined.
In the end I think it's quite a good idea to go through this hassle to have a valid model.
At least it helps getting rid of some obvious bugs with models.
So be sure not to forget beginInsertRows and friends Smiling
Have fun.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
icefox's picture

still finding bugs?

If you find bugs in your model that the modeltest could have found if it had only tested "X", feel free to e-mail me at ben@meyerhome.net and i'll try to add them to the model test.

-Benjamin Meyer

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.