<div class="gmail_quote">On Wed, Jun 3, 2009 at 12:08 PM, Phil Thompson <span dir="ltr"><<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Wed, 03 Jun 2009 17:37:29 +0200, "V. Armando Solé" <<a href="mailto:sole@esrf.fr">sole@esrf.fr</a>><br>
wrote:<br>
<div><div></div><div class="h5">> Hello,<br>
><br>
> The problem can be solved as shown below.<br>
><br>
> It seems the linux 32 bit implementation gets confused in<br>
> createIndex(row, column, a) when a is not an integer but a long. With<br>
> small values of a (10, 100, 1000), the indexId() method returns the<br>
> supplied value.<br>
><br>
> The solution is to call createIndex(row, column, a) with a being a<br>
> python object and not its id. The indexId() method can be masked with a<br>
> 32 bit mask if it returns a negative value. I have only found that<br>
> misbehavior under linux 32bit. Windows XP and linux 64-bit behave<br>
properly.<br>
><br>
> Thanks for your time,<br>
><br>
> Armando<br>
><br>
> import PyQt4.Qt as qt<br>
> import random<br>
> import sys<br>
><br>
> mask = 0xFFFFFFFF<br>
><br>
> class Model(qt.QAbstractItemModel):<br>
> def index(self, row, column, parent):<br>
> a=[random.random()]<br>
> index = self.createIndex(row, column, a)<br>
> print "Next two values should be the same"<br>
> returned = index.internalId()<br>
> if returned < 0:<br>
> returned = returned & mask<br>
> print "indexInternalId = ", returned<br>
> print "id(a) = ", id(a)<br>
> print "Forcing to be the same with a 32 bit mask"<br>
> print "indexInternalId = ", index.internalId() & mask<br>
> print "id(a) = ", id(a) & mask<br>
> return index<br>
><br>
> if __name__ == "__main__":<br>
> app = qt.QApplication([])<br>
> w = Model()<br>
> w.index(0,0,None)<br>
<br>
</div></div>Could you see if the problem goes away if you change qabstractitemmodel.sip<br>
so that...<br>
<br>
QModelIndex createIndex(int arow, int acolumn, int aid) const;<br>
<br>
...is replaced by...<br>
<br>
QModelIndex createIndex(int arow, int acolumn, quint32 aid) const;<br>
<font color="#888888"></font></blockquote><div><br>I applied this change to the 20090601 snapshot. Executive summary: when I check different data types, I can still find places where the two id's do not agree. I find disagreement with the mask applied and without:<br>
<br>When I run the script I posted, I get output like:<br><br>Next two values should be the same<br>indexInternalId = 1849945336 <br>id(a) = 139691366280440<br><br>If I apply Armando's mask, I get:<br><br>Next two values should be the same<br>
indexInternalId = 12719168<br>id(a) = 12719168<br><br>If I remove the mask and instead do "a=[numpy.uint32(random.random())]", I get ouput like:<br><br>Next two values should be the same<br>indexInternalId = 12719168<br>
id(a) = 12719168<br><br>Still without the mask, if I do "a=[numpy.int64(random.random())]":<br><br>Next two values should be the same<br>indexInternalId = 12719168<br>id(a) = 12719168<br><br>And finally, with Armando's mask and with "a=[numpy.int64(random.random())]":<br>
<br>Next two values should be the same<br>indexInternalId = 110072896<br>id(a) = 139754050917440<br><br>Darren<br></div></div>