[PyQt] Variant compare

Phil Thompson phil at riverbankcomputing.com
Fri Jun 5 11:44:23 BST 2009


On Fri, 05 Jun 2009 17:14:52 +0700, Alexandr N Zamaraev <tonal at promsoft.ru>
wrote:
> Snippet:
> Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit 
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> from PyQt4 import QtCore
>  >>> QtCore.QVariant(1) == QtCore.QVariant(1)
> True
>  >>> QtCore.QVariant(int) == QtCore.QVariant(int)
> False

Under the covers Python objects are wrapped in a class that manages their
reference counts so that you (and Qt internals) can safely copy QVariant
around. It's those wrappers that are being compared not the object that
they are wrapping.

It would be nice if the QVariant == operator could call the wrapper's ==
operator rather than just compare addresses.

>  >>> QtCore.QVariant([1, 2]) == QtCore.QVariant([1, 2])
> False
>  >>>
> Why?
> 
> sip-4.8-snapshot-20090603.zip
> PyQt-win-gpl-4.5-snapshot-20090601.zip

Phil


More information about the PyQt mailing list