[PyQt] multiple inheritance suggestion
Luke Campagnola
lcampagn at email.unc.edu
Sat Apr 14 15:11:47 BST 2012
On Sat, Apr 14, 2012 at 09:12, Phil Thompson <phil at riverbankcomputing.com>wrote:
> On Sun, 8 Apr 2012 22:40:04 -0400, Luke Campagnola
> <lcampagn at email.unc.edu>
> wrote:
> >As an example, consider the standard diamond
> > inheritance problem:
> >
> > A
> > / \
> > B C
> > \ /
> > D
> >
> > If A is a subclass of QObject, then presumably classes B, C, and D could
> > all define their own signals (creating an instance of class D should
> only
> > result in a single C++ QObject instance, so in theory this should work
> > fine).
>
> No, because Qt doesn't support it as it only handles "linear" chains of
> meta-objects.
>
>
Thanks, Phil, I didn't realize this was a limitation of Qt.
I did find an easy workaround, though: instead of defining class C as a
QObject subclass, I just give it a separate QObject attribute as a proxy
for sending and receiving signals. Looks like this:
class C:
class QObjectProxy(QObject):
sig = QtCore.pyqtSignal()
def __init__(self):
self.proxy = QObjectProxy()
self.sig = self.proxy.sig
Then for instances of class C, I can call c.sig.emit() or
c.sig.connect(...) in the usual way and this works well with multiple
inheritance.
Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120414/491cff18/attachment.html>
More information about the PyQt
mailing list