[PyQt] Comparing QString with QChar

Mark Summerfield mark at qtrac.eu
Fri Jun 27 09:38:04 BST 2008


Hi,

I got caught by this today:

    >>> from PyQt4.QtCore import *
    >>> s = QString("X")
    >>> c = QChar("X")
    >>> s[0] == c
    False
    >>> s[0] == QString(c)
    True

In C++/Qt if you do the s[0] == c comparison it will return true because
operator[] returns a const QChar &, but in PyQt4 s[0] is still a
QString---which makes sense because in Python a char is just a str of
length 1, but maybe this particular case could be handled more
intuitively?


-- 
Mark Summerfield, Qtrac Ltd., www.qtrac.eu




More information about the PyQt mailing list