[PyQt] QVariant TypeError on python class, but not on Qt class

Phil Thompson phil at riverbankcomputing.co.uk
Wed Apr 4 09:31:12 BST 2007


On Wednesday 04 April 2007 3:01 am, Drew Vogel wrote:
> Consider this listing:
>
>    1.
>       from PyQt4 import QtCore
>    2.
>       from PyQt4 import QtGui
>    3.
>
>    4.
>
>    5.
>       # This works
>    6.
>       i = QtGui.QIcon()
>    7.
>       qi = QtCore.QVariant(i)
>    8.
>
>    9.
>
>   10.
>       # This throws TypeError: argument 1 of QVariant() has invalid type
>   11.
>       class C:
>   12.
>               def __init__(self, v):
>   13.
>                       self.value = v
>   14.
>
>   15.
>       x = C(100)
>   16.
>       qx = QtCore.QVariant(x)
>
>
> Why does line 16 throw TypeError, but line 7 does not? I suspect that it
> has something to do with "x" being a python class and "i" being a Qt
> class, but I don't see anything in the QVariant documentation mentioning
> a difference. Is this supposed to be supported?

QVariant can only handle types it knows about (nothing to do with whether they 
are Qt classes). It knows nothing about C.

Phil


More information about the PyQt mailing list