[PyQt] Changing base class arguments

Phil Thompson phil at riverbankcomputing.com
Fri Aug 24 10:20:36 BST 2012


On Thu, 23 Aug 2012 16:37:45 +0200, Marco Meier <marco.meier at ifak.eu>
wrote:
> Hi,
> 
> i'm trying to wrap a C++ class with virtual methods using SIP. This
> class takes an auto_ptr pointing to another class as argument to the
> only defined constructor.
> 
> Without virtual methods, i used %MethodCode to create an object of this
> class using a const char * as argument. With virtual methods, this is
> not possible, since the constructor of the base class is called prior to
> the constructor.
> 
> Is there a way to change the initializer list to something like
> 
> sipwrapped_class(const char *a0) :
> wrapped_class(some_static_method(a0)), .. {}
> 
> or is there another way to do this with SIP?

The way to do it is to specify an explicit signature for the ctor and to
use %MethodCode...

typedef void *auto_ptr;

class Foo
{
public:
    Foo(const char *) [(auto_ptr)];
%MethodCode
        sipCpp = new sipFoo(some_static_method(a0));
%End
};

The only odd thing here is the auto_ptr typedef which is needed (although
never used in the generated code) because SIP needs to know a fundamental
type (but not necessarily the correct fundamental type) for every argument
of a C++ signature. I will change it so that the typedef isn't needed - but
it doesn't do any harm.

Phil


More information about the PyQt mailing list