[PyQt] How to derive from a %MappedType?

Phil Thompson phil at riverbankcomputing.com
Sun Jan 22 16:07:43 GMT 2017


On 22 Jan 2017, at 3:49 pm, Shaheed Haque <srhaque at theiet.org> wrote:
> 
> Hi all,
> 
> I'm having trouble with %MappedType with roughly the following in C++:
> 
> ================
> class Outer
> {
>    class Inner: KConfigSkeletonGenericItem<QString>
>    {
>    };
> };
> ================
> 
> Now, if a do a roughly literal translation to .sip, the SIP compiler
> flags a syntax error for the declaration of Inner. This seems to be
> caused by the "<QString>". I had understood that a %MappedType could
> be relied to fill in whereever it was encountered, even in a base
> class specifier but since the specification syntax suggest it looks
> for a simple name in the list of base classes, I tried inserting a
> "typedef" with the resulting .sip looking roughly like this (in
> practice, there is a %Module and some %Include'ing etc going on):
> 
> ================
> class Outer
> {
>    typedef KConfigSkeletonGenericItem<QString>
> KConfigSkeletonGenericItem_QString;
>    class Inner: KConfigSkeletonGenericItem_QString
>    {
>    };
> };
> 
> %MappedType KConfigSkeletonGenericItem<QString>
> {
> };
> ================
> 
> That addresses the syntax error, but now it complains
> "KConfigSkeletonGenericItem_QString has not been defined". (I also
> tried moving the %MappedType to before the Outer class, to no avail).
> 
> Have I misunderstood something basic about how %MappedType works, or
> something else incorrect?

%MappedType is used to specify the Python type that is used instead of a C++ class and the code to convert between them. SIP does not allow you to define sup-types of Python types.

Phil


More information about the PyQt mailing list