[PyQt] multiple inheritance and signals problem, mixin before QObject

Phil Thompson phil at riverbankcomputing.com
Sat Sep 14 17:05:40 BST 2013


On Thu, 12 Sep 2013 10:30:06 -0400, lloyd konneker <bootch at nc.rr.com>
wrote:
> This is an update to my previous post.
> Here is an abstract of the code for easier reading:
> 
> 
> class B(object):
>    def __init__(self):
>      self.a1 = A()
>      self.a1.signal1.connect(self.handler)    # Fails in PyQt, succeeds 
> in PySide
> 
>    def handler(self):
>      pass
> 
> 
> class A (Mixin, SubclassOfQObject):
>    def __init__(self):
>      super().__init__()
> 
> class Mixin(object):
>    signal1 = Signal()
>    def __init__(self):
>      super().__init__()
> 
> 
> 
> Again, AFAIK this works in PySide, but not in PyQt.
> The MRO of a1, an instance of class A, is (Mixin, SubclassOfQObject, 
> QObject, object).
> And Mixin.__init__ calls super, which calls QObject.__init__ for 
> instance a1,
> so the signal instance should be bound by the time its connect method is

> called?
> 
> I found that a workaround is to eliminate the mixin:
> 
> 
> class A (SubclassOfQObject):
>    signal1 = Signal()
>    def __init__(self):
>      super().__init__()
> 
>    ... methods that were in Mixin ...
> 
> 
> I just don't understand why.  Should I submit an executable test case?

PyQt emulates the Qt behaviour - signals can only be defined in QObject
sub-classes. The error message assumes that Qt classes are always the first
super-class.

Phil


More information about the PyQt mailing list