[PyQt] Possible bug with new signal-slot connection

Alexander Bruy alexander.bruy at gmail.com
Thu May 17 06:28:49 BST 2012


Hi Phil,

many thanks for detailed explanation. You are right making
significant changes in old code that can break compatibility
or stability is no good. But it will good to add this explanation
to documentation.

2012/5/16 Phil Thompson <phil at riverbankcomputing.com>:
> This is what's happening...
>
> PyQt allows connections to be made to any Python callable.
>
> With old style connections a proxy slot is created under the covers
> whenever a callable is used (as opposed to when SLOT() is used to refer to
> a C++ slot). Therefore, in your example, a proxy is always created for the
> connection to Dialog.reject even though that refers to the object that
> wraps the C++ slot (as there is no Python reimplementation of reject()).
>
> New style connections are a bit smarter in that they treat slot objects
> that refer to a wrapped C++ slot and objects that refer to some real Python
> code differently - a proxy is only created in the latter case.
>
> A possible workaround might be to add a null implementation of reject() to
> the BugDemo class...
>
>  def reject(self):
>    super(BugDemo, self).reject()
>
> ...which would force new style connections to create a proxy - and for
> disconnect() to assume that a proxy was being used.
>
> So the rule is that if you make a connection old style then you must
> disconnect old style as well and the same for new style. You also need to
> be aware that pyuic4 uses old style connections.
>
> I accept that this is a bug, but I don't want to fix it. The reason is
> that the changes required to the old style support code would be quite
> significant and I don't think the risk to the stability of that code is
> worth it at this stage of the life of PyQt4, particularly as the workaround
> is straightforward. This bug has been present for 3 years and it's the
> first time I remember it being reported. Obviously I will update the
> documentation.
>
> Phil

Thanks again
-- 
Alexander Bruy


More information about the PyQt mailing list