[PyQt] How to derive from a %MappedType?
Shaheed Haque
srhaque at theiet.org
Sun Jan 22 16:26:22 GMT 2017
So, since SIP only supports templates via %MappedTypes, I guess there
is there any way to express the relationship
class Foo: TemplatedType<whatever>
Omitting the base would presumably "hide" any methods etc. that the
templated type might have contributed to the API of Foo...am I right
in thinking that the only option is to omit the base and add to Foo
anything which is needed?
On 22 January 2017 at 16:07, Phil Thompson <phil at riverbankcomputing.com> wrote:
> 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