On 8/21/12 5:47 PM, Nikos Chantziaras wrote: > On 21/08/12 23:55, Stephen Chu wrote: >> On 8/21/12 4:26 PM, Nikos Chantziaras wrote: >>> On 21/08/12 22:45, Stephen Chu wrote: >>>> On 8/21/12 3:35 PM, Christoph Feck wrote: >>>>> On Tuesday 21 August 2012 20:55:00 Stephen Chu wrote: >>>>>> Is there a way to store a 64-bit internal ID in QModelIndex? The >>>>>> function QModelIndex::internalId() returns a 64-bit number but >>>>>> there's no way to put one in. The constructor takes only a 32-bit >>>>>> integer. >>>>> >>>>> Try using the overload that takes the void * pointer. The return value >>>>> is 64 bit, because pointers can also be 64 bit, and C++ doesn't allow >>>>> different overloads with different return values. >>>> >>>> Thanks for the help. But my app is currently 32-bit. :( >>> >>> Would a pointer to a qint64 work? >> >> Yes, it will. I was thinking about that but got stuck trying to figuring >> out how I can manage the memory since QModelIndedx does not own the >> object/memory pointed by the void* >> >> Say I allocate a QList<int64_t> and create indices with internal pointer >> pointing to elements in the list. When I need to update the model from >> external data, I will have to re-allocate the list and the existing >> pointers will be left dangling. What is the proper steps to update the >> model data in this case? > > Note that I didn't work with QAbstractItemModel before, so perhaps I'm > not the most suitable person here to give advice. With that being said, > you might be able to allocate like this: > > createIndex(row, column, new qint64(value)); > > Access the value with: > > *(qint64*)internalPointer(); > > And when you don't need the QModelIndex anymore, you deallocate like this: > > delete (qint64*)internalPointer(); > > You should probably create wrappers for those operations. Or work out a > subclass model. > > But again, I didn't work with that part of Qt before, so I might be > talking gibberish here ;-) >
Actually it makes a lot of sense and I was trying to do the same. But I can not find out when a QModelIndex is no longer in use. _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest