[PyQt] Re: [PyKDE] Re: QAbstractItemModel 64 bit problem

Phil Thompson phil at riverbankcomputing.co.uk
Thu Apr 5 18:48:14 BST 2007

On Thursday 05 April 2007 6:09 pm, Jeremy Sanders wrote:
> Phil Thompson wrote:
> > This is the correct behaviour.
> >
> > On 64 bits int is 4 bytes and long and void* are 8 bytes. Python ints are
> > actually C longs. The value of id() is greater than 4 bytes so you lose
> > bits when you call createIndex().
> Thanks for the response - I thought that might be the case. I was just
> surprised that there wasn't an exception, though I imagine it would be very
> slow to check every parameter was within int bounds.
> Looking at the trolltech docs for qt4.2, it appears internalId() returns a
> qint64 now. Should this mean that internalId() should now work with 64 bit
> python Ids?

No, I think it's always returned a qint64. The problem is that createIndex() 
takes an int - that's where the bits are lost.

What's needed is that both should use a long.

In fact I could make this work with PyQt so that id() could be used as the 
internal ID, but I don't really see the point as...

    idx = a.createIndex(0, 0, data)
    assert idx.internalPointer() is data

...seems more natural than...

    idx = a.createIndex(0, 0, id(data))
    assert idx.internalId() == id(data)

...and both require you to keep a reference elsewhere to data.


More information about the PyQt mailing list