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

Demetrius Cassidy dcassidy36 at mass.rr.com
Sun Jul 19 19:01:17 BST 2009


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>

-- 
View this message in context: http://www.nabble.com/PyQt4.5.2-QVariant.toPyObject%28%29-bugged-%28code-included%29-tp24559310p24559310.html
Sent from the PyQt mailing list archive at Nabble.com.



More information about the PyQt mailing list