[PyQt] inheriting from QObject and dbus.service.Object

Phil Thompson phil at riverbankcomputing.com
Wed Aug 12 09:23:07 BST 2009


On Wed, 12 Aug 2009 10:05:26 +0200, Marcos Dione <mdione at grulic.org.ar>
wrote:
> On Tue, Aug 11, 2009 at 09:21:37AM +0100, Phil Thompson wrote:
>> On Tue, 11 Aug 2009 07:54:35 +0200, Marcos Dione <mdione at grulic.org.ar>
>> wrote:
>> > In [8]: class A (dbus.service.Object, QObject): pass
>> > TypeError: Error when calling the metaclass bases
>> >     metaclass conflict: the metaclass of a derived class must be a
>> >     (non-strict)
>> >     subclass of the metaclasses of all its bases
>> > 
>> >     is it possible to inherit from both? or will I have to make
another
>> >     class
>> > for this?
>> 
>> You can't inherit from both for the reason given. I don't know enough
>> about
>> DBus to know what the best solution is.
> 
>     ok, let me put it this way. does PyQt build any metaclass for the
>     QObject
> class or any other class which it might inherit from? I tried to figure
> this 
> out from the source but between sip and the generated code they managed
to 
> confuse me enough to ask for help :) if not, I'll try to play with it a
> little 
> more, and if i fail, just create another class as a wrapper.

PyQt defines its own metaclass (as "print type(QObject)" demonstrates).

It's a fundamental problem with Python's implementation that you get
meta-class conflicts that prevent you using multiple inheritance when you
might want to. It would be nice to be able to (somehow) specify multiple
meta-class calls in a similar way that a derived class's __init__
explicitly calls the __init__ of each of its super-classes.

Phil


More information about the PyQt mailing list