[PyQt] Bug in QAbstractItemModel::createIndex()?

Phil Thompson phil at riverbankcomputing.co.uk
Thu Apr 5 22:24:58 BST 2007

On Thursday 05 April 2007 6:42 pm, Andreas Pakulat wrote:
> On 05.04.07 17:19:56, Phil Thompson wrote:
> > On Thursday 05 April 2007 3:02 pm, Andreas Pakulat wrote:
> > > Well, the problem with internalPointer is that you can't easily check
> > > wether the object it carries is valid. With internalId you get an
> > > KeyError when trying to index into the dict...
> >
> > An internal pointer is always valid if you still have a reference to the
> > actual data.
> Yes, but if you don't have a reference anymore to an object, you can
> still access internalPointer() and try to do something with whatever it
> returns -> crash. With an internalId you get a nice exception which can
> be caught.

No you don't. The exception you are seeing is because you are assuming that 
internalId() will return the id() you passed to createIndex(). Because it 
doesn't (in certain cases on certain platforms) you have "lost" it in your 

> > The internal ID would be useful if the value returned by internalId() was
> > the same size (ie. an int) as that passed to createIndex().
> My Qt4.3 docs say createIndex takes a quint32 now, while internalId()
> returns a quint64. Now if thats not strange I don't know what is... I
> guess I should report this to TT. Would it be better to have a quint32
> or a quint64 here?

Given the internal implementation it has to be something that is no bigger 
than a void* - that rules out quint64. For it to work with id() it would have 
to be a long.

> > > Uhm, I just tested the following code, maybe this helps in finding the
> > > cause. The output here is:
> > > -1211419440 3083330668 3083330668
> >
> > The first number makes no sense. I would expect it to be -1211636628.
> I guess -121163... is the negative max of an int in 32bit? Anyway, what
> I find weird is that internalPointer == id in this case, while this
> obviously doesn't work in real world examples
> > You could put printf()s in the SIP generated code to make absolutely
> > sure. Look for the function meth_QAbstractItemModel_createIndex(). The
> > only way it could be happening is if the convertion to an int raised an
> > exception.
> Tried printfs and fprintfs (to stderr), but I don't see anything when
> running the python application... sip+PyQt4 is built in debug mode, do I
> need to do something else?

No - assuming you've put them in the right place and installed it.


More information about the PyQt mailing list