[PyQt] PyQt4.5.2 QVariant.toPyObject() bugged (code included)

Phil Thompson phil at riverbankcomputing.com
Mon Jul 20 12:31:22 BST 2009


On Sun, 19 Jul 2009 11:01:17 -0700 (PDT), Demetrius Cassidy
<dcassidy36 at mass.rr.com> wrote:
> For some reason as of 4.5.2, QVariant is behaving much differently than
> from
> 4.5.1. It seems that if I have a QVariant with a python list or tuple,
that
> doing toPyObject() on the QVariant object return a python list of
> QVariants!! This means for each item in my list, I would also need to do
a
> .toPyObject!
> 
> This is completely different behavior than how it worked in 4.5.1, where
> doing toPyObject would return the original list of strings, not a list of
> QVariants.
> 
> Test Code:
> 
> from PyQt4.QtCore import QVariant
> 
> def testVariant():
> 	var = QVariant(['one', 'two', 'three'])
> 
> 	varObj = var.toPyObject()
> 
> 	print "checking if varObject is of type list"
> 	print(isinstance(varObj, list))
> 
> 	for item in varObj:
> 		print(item)
> 
> 
> testVariant()
> 
> 
> Output:
> 
> checking if varObject is of type list
> True
> <PyQt4.QtCore.QVariant object at 0x012A97D8>
> <PyQt4.QtCore.QVariant object at 0x012A9810>
> <PyQt4.QtCore.QVariant object at 0x012A9848>

Should be fixed in the current SIP and PyQt snapshots. Note that
toPyObject() will return a list of QStrings, not a list of Python strings -
it doesn't return the original list.

If you can confirm there are no other problems I'll make a new release in a
day or two.

Phil


More information about the PyQt mailing list