[PyQt] Fwd: Mixin classes and PyQt4

Phil Thompson phil at riverbankcomputing.com
Sun Feb 16 13:27:58 GMT 2014


On 13-02-2014 6:54 pm, Martin Teichmann wrote:
> Hi Baz, Hi Phil, Hi List,
>
>> This actually only relates to multiple-inheritance. It should never
>> be problem for true mixin classes.
>
> There youre certainly right. Its calling super() where I have my
> issues. Your examples did not call super(), so the MRO doesnt
> matter.
>  
>
>> The one genuine issue with mixins in PyQt, is that you cannot
>> inherit custom signals.
>
> Then it might be interesting for you that with my patch applied, it
> does work. For example:
>
> 
> -----------------------------------------------------------------------
> from PyQt4.QtGui import QWidget, QLabel, QApplication
>  from PyQt4.QtCore import pyqtSignal, QObject
>
> class A(QObject):
>     a = pyqtSignal(str)
>
> class B(A, QLabel):
>     b = pyqtSignal(str)
>
> class Printer(QObject):
>     def print(self, a):
>         print(a)
>
> app = QApplication([])
>
> b = B()
> p = Printer()
> b.a.connect(p.print)
> b.b.connect(p.print)
> b.a.emit(a)
> b.b.emit(b)
> b.setText(foo)
> 
> ----------------------------------------------------------------------
>
> correctly works with my patch applied. It does not if you let A
> inherit from object.

At the moment (having just started to think about it again) I'm against 
your original patch as it is too different to the C++ behaviour.

However I do like your other patch which raised an exception when 
inheriting from more than one C++ class.

> I thought that this is because QObject has a special metaclass
>  which does something to the signals, but replacing the definition
> of A with class A(object, metaclass=QObject.__class__)
> interestingly did not help.
>
> Btw, why is it called pyqtSignal and not just signal, for those
> in need for details they could just write QtCore.signal

In case QObject was given a signal() method at some point.

Phil



More information about the PyQt mailing list