[PyQt] Qt or PyQt problem?

Phil Thompson phil at riverbankcomputing.com
Wed Jun 3 17:08:13 BST 2009


On Wed, 03 Jun 2009 17:37:29 +0200, "V. Armando Solé" <sole at esrf.fr>
wrote:
> Hello,
> 
> The problem can be solved as shown below.
> 
> It seems the linux 32 bit implementation gets confused in 
> createIndex(row, column, a) when a is not an integer but a long. With 
> small values of a (10, 100, 1000),  the indexId() method returns the 
> supplied value.
> 
> The solution is to call createIndex(row, column, a) with a being a 
> python object and not its id. The indexId() method can be masked with a 
> 32 bit mask if it returns a negative value. I have only found that 
> misbehavior under linux 32bit. Windows XP and linux 64-bit behave
properly.
> 
> Thanks for your time,
> 
> Armando
> 
> import PyQt4.Qt as qt
> import random
> import sys
> 
> mask = 0xFFFFFFFF
> 
> class Model(qt.QAbstractItemModel):
>   def index(self, row, column, parent):
>       a=[random.random()]
>       index =  self.createIndex(row, column, a)
>       print "Next two values should be the same"
>       returned = index.internalId()
>       if returned < 0:
>           returned = returned & mask
>       print "indexInternalId = ", returned
>       print "id(a) = ", id(a)
>       print "Forcing to be the same with a 32 bit mask"
>       print "indexInternalId = ", index.internalId() & mask
>       print "id(a) = ", id(a) & mask
>       return index
> 
> if __name__ == "__main__":
>   app = qt.QApplication([])
>   w = Model()
>   w.index(0,0,None)

Could you see if the problem goes away if you change qabstractitemmodel.sip
so that...

    QModelIndex createIndex(int arow, int acolumn, int aid) const;

...is replaced by...

    QModelIndex createIndex(int arow, int acolumn, quint32 aid) const;

Phil


More information about the PyQt mailing list