[PyQt] How does sipParseArgs skip arguments?

Phil Thompson phil at riverbankcomputing.com
Mon Apr 17 09:37:08 BST 2017


On 16 Apr 2017, at 12:55 pm, Shaheed Haque <srhaque at theiet.org> wrote:
> 
> When using %MethodCode, the SIP-generated part of the output generally
> includes a call to sipParseArgs. Now, the documentation for
> %MethodCode explains the use of sipArgs as a tuple, so it is clear
> that handwritten code for argument N should extract the N'th entry in
> sipArgs and proceed as required.

No. You should always refer to the arguments as 'a0', 'a1' etc.

> What I'd like to understand is how sipParseArgs knows to skip an
> argument which is to be handled manually? For example (using SIP 4.18)
> and these two similar functions:
> 
>    KEmoticonsTheme newTheme(const QString &name, KService &service,
> bool dummy);
>    KEmoticonsTheme newTheme2(const QString &name, const
> QExplicitlySharedDataPointer<KService> &service, bool dummy)
>    [KEmoticonsTheme(const QString &name, const
> QExplicitlySharedDataPointer<KService> &service, bool dummy)];
> %MethodCode
> // TBD
> %End
> 
> The first function gets its arguments like this:
> 
> =====================
>       const QString* a0;
>        int a0State = 0;
>        KService* a1;
>        bool a2;
>        KEmoticons *sipCpp;
> 
>        if (sipParseArgs(&sipParseErr, sipArgs, "BJ1J9b", &sipSelf,
> sipType_KEmoticons, &sipCpp, sipType_QString,&a0, &a0State,
> sipType_KService, &a1, &a2))
> =====================
> 
> whereas the second version skips a1 like this:
> 
> =====================
>        const QString* a0;
>        int a0State = 0;
>        QExplicitlySharedDataPointer<KService> a1;
>        bool a2;
>        KEmoticons *sipCpp;
> 
>        if (sipParseArgs(&sipParseErr, sipArgs, "BJ1b", &sipSelf,
> sipType_KEmoticons, &sipCpp, sipType_QString,&a0, &a0State, &a2))
> =====================
> 
> I need to generate the code to extract a1 from sipArgs, but in
> general, what are the rules that govern whether sipParseArgs will or
> will not extract arguments? And in the second case, how does it know
> to extract a0 and then a2, but not a1?

I'm guessing that #2 is because you got an error message saying that you had to provide %MethodCode and a C++ signature. The reason is that SIP does not understand the signature as a Python signature. There is no point in providing explicit Python and C++ signatures if they are the same. You need to provide a Python signature that corresponds to what the Python programmer will be using (or provide a mapped type for the problematic argument). The purpose of the %MethodCode is to provide the bridge between the Python signature and the C++ signature.

Yes - the error reporting could be improved.

Phil


More information about the PyQt mailing list