[Qt-interest] QModelIndex problems to represent a given data structure

Justus Best just18 at gmx.de
Mon Jul 5 17:39:44 CEST 2010


  Hi,

I have some problems to display a hierarchic data structure with the Qt 
Model/View concept.

The main problem is that it is not possible to identify which type the 
internal-pointer has. If I could use the internal-pointer in combination 
with the internal-id it would be easy to cast to the right type.

Btw. it's not clear to me why the create-index function in 
QAbstractItemModel takes an quin32 as id parameter and the QModelIndex 
returns a qint64 as internal-id.

Hope it gets clear what my Problem is. I'm at the moment thinking of 
some possible Solutions,

1. Overwriting the createIndex() function to create an index with 
pointer and Id.
2. Subclassing QModelIndex to add type safety
3. Mirroring the given data structure into a lightweight private data 
structure which only keeps references to the given data structure which 
can always be casted into the same type, like the example in the qt docs.
4.throwing away the qt model view concept and writing my own tree based 
display widget.
5. Somehow create an index which is able to identify an item in the 
given data structure.
6. A better solution you can provide :p

What are your opinions to that ? I really hope that I don't have to use 
solution 3-5.

Justus




More information about the Qt-interest-old mailing list