[PyQt] chain signals, disconnecting an "emit" slot

Luke Lee durdenmisc at gmail.com
Mon Apr 15 17:02:19 BST 2013


As mentioned here,
http://www.riverbankcomputing.com/pipermail/pyqt/2011-October/030578.html,
you cannot use the 'disconnect' method to disconnect something when the
signals were connected via the emit() method.

I'm curious about the details of why connecting signals to the emit()
method does not work.  I've tried to do some debugging myself, but I'm
still a bit confused.

It looks as though the pyqtSignal object **changes** during the course of a
running application.  For example, consider the following line:

ok.pressed.connect(cancel.pressed.emit)

As previously mentioned doing a disconnect like the following doesn't work:

ok.pressed.disconnect(cancel.pressed.emit)

I've tried debugging by printing the id() of the cancel.pressed object
(pyqtSignal) as well as the id() of the cancel.pressed.emit method.  These
object ids actually **change** between when I connect and later try to
disconnect.

I've verified that I'm not deleting the objects, etc.  Also, calling
cancel.pressed.emit() works as you can imagine even though it's seemingly a
different object than the one that was connected earlier.  What exactly is
happening here?

I'm assuming it has something to do with the wrapping of the C++ code and
maybe the QMetaObject (http://qt-project.org/doc/qt-4.8/qmetaobject.html)
is involved somehow.

I'm really just trying to understand why these ids don't match up and why
connecting signals to signals is preferred vs. connecting to the emit
method.  I can easily change my code to connect the signals via the
preferred method, but I felt like there was a useful lesson to learn here.
 Thoughts?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130415/a31b99c3/attachment-0001.html>


More information about the PyQt mailing list