AW: SIP translate Union
Marian Thomsen
marian.th at outlook.de
Thu Nov 26 08:08:30 GMT 2020
Thank you for the advice!
Unfortunately I cant get a simple example to work.
I have a simple union in the header test_union.h
union {
int test1;
int test2;
} u;
And this is the best I got so far in the .sip file:
struct union{
%TypeHeaderCode
#include <test_union.h>
%End
int *test1 {
%GetCode
sipPy = PyLong_FromLongLong(sipCpp->test1)
if(sipPy == NULL)
sipPy = NULL;
%End
%SetCode
if (PyLong_Check(sipPy))
sipCpp->test1;
else
sipErr = 1;
%End
};
int *test2 {
%GetCode
sipPy = PyLong_FromLongLong(sipCpp->test2);
if(sipPy == NULL)
sipPy = NULL;
%End
%SetCode
if (PyLong_Check(sipPy))
sipCpp->test2;
else
sipErr = 1;
%End
};
}u;
I get a syntax error in the last line and have tried to write it so that sip would understand it, but also with something like:
typedef struct union union;
union u{ ... };
I got no luck so far. Am I completly wrong?
Some advice would be appreciated
Thank you!
M.T.
________________________________
Von: Phil Thompson <phil at riverbankcomputing.com>
Gesendet: Montag, 23. November 2020 11:48
An: Marian Thomsen <marian.th at outlook.de>
Cc: pyqt at riverbankcomputing.com <pyqt at riverbankcomputing.com>
Betreff: Re: SIP translate Union
On 23/11/2020 10:40, Marian Thomsen wrote:
> Hello,
>
> I’m trying to use SIP to translate an union. Just started using SIP
> and because unions are not supported directly I cant find a way to
> translate them.
> What would be a good approach?
> I’m trying to use %MappedType but cant get it to work.
>
> A simple example would be really appreciated!
The most direct translation would be to wrap it as a struct and
implement %GetCode and %SetCode for each of the union elements.
Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20201126/27ba8861/attachment.htm>
More information about the PyQt
mailing list