[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] multiple inheritance suggestion
From: Luke Campagnola <lcampagn () email ! unc ! edu>
Date: 2012-04-14 14:11:47
Message-ID: CACZXET-iwGW_e_6RAtt3pptKE5sPim1HppGd+6K5vz46JRKVew () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
On Sat, Apr 14, 2012 at 09:12, Phil Thompson <phil@riverbankcomputing.com>wrote:
> On Sun, 8 Apr 2012 22:40:04 -0400, Luke Campagnola
> <lcampagn@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
[Attachment #5 (text/html)]
<br><br><div class="gmail_quote">On Sat, Apr 14, 2012 at 09:12, Phil Thompson <span \
dir="ltr"><<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>></span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex">
On Sun, 8 Apr 2012 22:40:04 -0400, Luke Campagnola<br>
<<a href="mailto:lcampagn@email.unc.edu">lcampagn@email.unc.edu</a>><br>
wrote:<br>
<div class="im">>As an example, consider the standard diamond<br>
> inheritance problem:<br>
><br>
> A<br>
> / \<br>
> B C<br>
> \ /<br>
> D<br>
><br>
> If A is a subclass of QObject, then presumably classes B, C, and D could<br>
> all define their own signals (creating an instance of class D should<br>
only<br>
> result in a single C++ QObject instance, so in theory this should work<br>
> fine).<br>
<br>
</div>No, because Qt doesn't support it as it only handles "linear" \
chains of<br> meta-objects.<br>
<div class="im"><br></div></blockquote><div><br></div><div>Thanks, Phil, I didn't \
realize this was a limitation of Qt. </div><div><br></div><div>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:</div>
<div><br></div></div><blockquote style="margin:0 0 0 \
40px;border:none;padding:0px"><div class="gmail_quote"><div>class C:</div><div> \
class QObjectProxy(QObject):</div><div> sig = \
QtCore.pyqtSignal()</div><div><br>
</div><div> def __init__(self):</div><div> self.proxy = \
QObjectProxy()</div><div> self.sig = \
self.proxy.sig</div><div><br></div></div></blockquote>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.<div>
<br></div><div>Luke<br><blockquote style="margin:0 0 0 \
40px;border:none;padding:0px"><div \
class="gmail_quote"><div><br></div><div><br></div></div></blockquote></div>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic