[Qt-interest] QModelIndex - boost::shared_pointers

Brad Howes howes at ll.mit.edu
Thu Sep 10 16:17:08 CEST 2009


On Sep 10, 2009, at 1:09 AM, Andreas Pakulat wrote:

> On 09.09.09 19:02:29, Willy P wrote:
>> Any advice for ways of using boost::shared_pointers w/ the Qt Model
>> View Framework?  It looks like they use a lot of raw pointers for
>> identification.  Is there no way around this?  Thanks for your
>> advice...
>
> As its part of the API, no. A QModelIndex' internal pointer will  
> always
> be void*.


And so you could just use the get() method of the shared_ptr interface  
and store in the ModelIndex the raw pointer. Remember that you don't  
have to worry about reference counting the QModelIndex, unless you are  
caching them and the documentation explicitly states not to do that.  
So, just create them from within your model, supplying a pointer to  
the object you want from the shared pointer and be happy. When you  
remove your object from a container, the shared_ptr class will of  
course dispose of it at the appropriate time, but since you cannot  
generate a QModelIndex from your container with that pointer value,  
you are safe.

Brad

-- 
Brad Howes
Group 42
MIT Lincoln Laboratory • 244 Wood St. • Lexington, MA 02173
Phone: 781.981.5292 • Fax: 781.981.3495 • Secretary: 781.981.7420








More information about the Qt-interest-old mailing list