PDA

View Full Version : Expected lifetime of QModelIndex?



Ishark
15th August 2007, 21:07
Hello,
I'm building a custom model for some tree-shaped data, and I'm not sure if I'm doing something bad or not.... When I create a QModelIndex to reference one of my data elements, how long is the QModelIndex supposed to be valid?

What I mean is: I'm using the internalId() property of the QModelIndex to be able to get back
at my data, so for example, the 5th object inside the 3rd top-level object would get an internal Id equal to 503 (03 => 3rd toplevel, 5xx -> 5th inside it). Now, if one more object is added inside the 3rd top level object, say at row position 1, then this internalId does not point to the same data anymore. Can I assume that any QModelIndex the model returns is not meant to survive across model data changes? Or must I ensure that my items have unique persistent identifiers and use them in creating the internalId?
Thanks in advance.

wysota
15th August 2007, 22:18
QModelIndex should be considered volatile - never store it anywhere for later use. You can use QPersistentModelIndex if you really can't live without it.