[PyQt] QGraphicsObject - Possible regression in PyQt5

Phil Thompson phil at riverbankcomputing.com
Wed Feb 10 13:36:33 GMT 2016


On 10 Feb 2016, at 11:38 am, Ales Erjavec <ales.erjavec324 at gmail.com> wrote:
> 
> On Sat, Feb 6, 2016 at 11:29 AM, Phil Thompson
> <phil at riverbankcomputing.com> wrote:
>> On 4 Feb 2016, at 10:21 am, Ales Erjavec <ales.erjavec324 at gmail.com> wrote:
>>> 
>>> Hello,
>>> 
>>> There seems to be a regression in PyQt5 when using QGraphicsObject
>>> in a pyqtSignal definition.
>>> 
>>> When a signal is defined in a QObject as `signal = pyqtSignal(QGraphicsObject)`
>>> the resulting meta object method will have a signature of
>>> 'signal(QGraphicsItem*)',
>>> but in PyQt4 this would have been 'signal(QGraphicsObject*)'.
>>> 
>>> Worse when the signal is actually emitted with an instance of a QGraphicsObject
>>> the receivers all get a None instead of the intended instance.
>>> This worked in PyQt4.
>> 
>> Should be fixed in tonight's snapshot.
>> 
>> Thanks,
>> Phil
> 
> Testing on OSX with Python 3.5 and PyQt 5.5.2-snapshot-d304857728a3
> the signal signature is 'signal(QGraphicsObject*)' and the emitted
> argument is not None,
> but unfortunately is of a wrong type (QtWidgets.QKeyEventTransition).
> 
> ########
> 
> from PyQt5 import QtWidgets, QtCore
> 
> print("Using PyQt", QtCore.PYQT_VERSION_STR)
> 
> 
> class GraphicsObj(QtWidgets.QGraphicsObject):
>    def paint(self, painter, option, widget):
>        pass
> 
>    def boundingRect(self):
>        return QtCore.QRectF()
> 
> 
> class Obj(QtCore.QObject):
>    signal = QtCore.pyqtSignal(QtWidgets.QGraphicsObject)
> 
> 
> meta = Obj.staticMetaObject
> method = meta.method(meta.methodCount() - 1)
> print("signal's signature:", bytes(method.methodSignature()).decode("ascii"))
> # -> 'signal(QGraphicsObject*)'
> 
> def log(item):
>    print("signal did emit with:", item)
> 
> obj = Obj()
> obj.signal.connect(log)
> #obj.signal.connect(log)
> #obj.signal[QtWidgets.QGraphicsObject].connect(lambda item:
> print("item:", item))
> 
> gitem = GraphicsObj()
> obj.signal.emit(gitem)
> # -> signal did emit with: <PyQt5.QtWidgets.QKeyEventTransition object at ...
> 
> #####
> 
> Note: If I connect the `obj.signal` to a second slot (commented out in
> the example code)
> the process terminates with a segmentation fault

I can't reproduce the problem...

Using PyQt 5.5.2-snapshot-3df32493cb78
signal's signature: signal(QGraphicsObject*)
signal did emit with: <__main__.GraphicsObj object at 0x10427eaf8>
signal did emit with: <__main__.GraphicsObj object at 0x10427eaf8>
item: <__main__.GraphicsObj object at 0x10427eaf8>

Make sure everything has been recompiled.

Phil


More information about the PyQt mailing list