[email protected]
[Top] [All Lists]

Re: QModelIndex quirk

Subject: Re: QModelIndex quirk
From: Ian Reinhart Geiser
Date: Wed, 5 Apr 2006 07:23:39 -0400
On Wednesday 05 April 2006 01:33 am, you wrote:
> Hello Ian,
> QModelIndex only provides a data() function because it is a temporary
> object. The documentation says that you should never save that indices.
> The model has a setData() function where you have a QModelIndex
> parameter and the data as QVariant.
> Use this function...
Yes, you are correct at least in syntax ;) Unfortunately the point is that my 
question was more into why isn't there a setData method on the QModelIndex.  
The issue you have is that sometimes you dont know what your model is if you 
are in a method that is ONLY dealing with the QModelIndex.  Temporary or not, 
it will still be around long enough to read, and in my case write.  Currently 
what I am forced to do is 
const_cast<QAbstractItemModel*>(index.model())->setData(index, mydata);

Looks wrong, right ;)  But the alternative is storing BOTH the source model 
and the index.   Keep duplicate data in sync, and worse, store a pointer to 
an object I only need for one method in a class.  Even more annoying, all of 
my methods that update the view must take both the index and the model.

        -ian reinhart geiser

To unsubscribe - send a mail to [email protected] with 
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>