[PyQt] Two base classed inherit QWidget

Frédéric frederic.mantegazza at gbiloba.org
Mon Feb 2 13:29:26 GMT 2009


Le 2/2/2009, "dboddie at trolltech.com" <dboddie at trolltech.com> a écrit:

>This is probably related to the restriction in C++ that you can only inherit
>from one QObject-based class when using multiple inheritance. This is partly
>due to the limitations of the meta-object system, but problems also arise as
>a result of the parent-child memory management mechanism.

As I was looking for a multiple inheriting method with Qt, someone
proposed me the following solution:

class A(Qt1) :
    def __init__(self, b, *p, **pp) :
        Qt1.__init__(self, *p, **pp)
        self.b_ = b

    # wrap B methods (both defined in B and Qt2 classes) to current class
    def method_1(self, *p, **pp):
        return self.b_.method_1(*p, *pp)
    def method_2(self, *p, **pp):
        return self.b_.method_2(*p, *pp)
    def method_3(self, *p, **pp):
        return self.b_.method_3(*p, *pp)

class B(Qt2) :
    def __init__(self, ....)
        Qt2.__init__(self, ...)

a = A(B(...), ...)

I didn't make test yet; do you think it is a useable solution?

--
   Frédéric



More information about the PyQt mailing list