[Qt-interest] QModelIndex - boost::shared_pointers

Willy P willy.lists at gmail.com
Thu Sep 10 19:17:47 CEST 2009


Brad, thanks a lot.

Another quick question, when indexing using internal id's,
QAbstractItemModel::createIndex takes a 32 bit id and
QModelIndex::internalId returns a 64 bit id.  Why is that?

-Willy


On Thu, Sep 10, 2009 at 7:17 AM, Brad Howes <howes at ll.mit.edu> wrote:
>
> 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
>
>
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>




More information about the Qt-interest-old mailing list