[PyQt] Strange behaviour with string conversions when emitting signals with dicts
Stefan Scherfke
stefan.scherfke at uni-oldenburg.de
Wed Apr 7 08:57:39 BST 2010
Hello,
yesterday I noticed a strange behavior with PyQt4 when I emit a signal, that has a dict with string-keys as argument.
Take the following example:
from PyQt4 import QtCore
class A(QtCore.QObject):
sig = QtCore.pyqtSignal(dict)
def run(self):
self.sig.emit({'a': [1, 'b']})
class Main(object):
def __init__(self):
self.obj = A()
self.obj.sig.connect(self.echo)
self.obj.run()
def echo(self, obj):
print obj
if __name__ == '__main__':
Main()
Until PyQt 4.7 (on my Mac and until last week on my other machine), the (expected) output was:
{'a', [1, 'b']}
But since I got an update to PyQt 4.7.2 on my Kubuntu machine, the (unexpected) output is:
{PyQt4.QtCore.QString(u'a'): [1, PyQt4.QtCore.QString(u'b')]}
If I change the signal definition in class B to
sig = QtCore.pyqtSignal('PyQt_PyObject')
the output is again:
{'a', [1, 'b']}
But "pyqtSignal(dict)" was a much more intuitive/pythonic way to define the signal.
Was this intuitive behavior of PyQt <= 4.7 a bug that was fixed in 4.7.2 or is this a new bug introduced with PyQt 4.7.2?
I can’t imagine that this change is a new “feature”, because it broke my whole application which should not happen with a bugfix release like 4.7.2.
Best regards,
Stefan
More information about the PyQt
mailing list