[PyQt] dense about qvariant and dict

David Cortesi davecortesi at gmail.com
Sat Dec 8 00:06:28 GMT 2012


OK, I implement QListView.itemData() returning a python dict,
which then arrives at QListView.setItemData() as a QVariant
of length 1. The problem is, how to cast that qv back to a dict?
I have read

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qvariant.html

and noted especially the .convert method, but qv.convert(dict) produces
the amusingly self-referential error,

TypeError: QVariant.convert(Type): argument 1 has unexpected type 'type'

dict(qv) doesn't do it. qv.toHash produces an empty dict.
qv.toMap produces a QMap with the original keys as QStrings and
the original data as QVariants. OK, but I'd rather have the python
dict -- is there a way to get it, or do I have to work with the QMap form?

Sorry to be so dense,

Dave Cortesi


More information about the PyQt mailing list