[PyQt] fixed size array

Phil Thompson phil at riverbankcomputing.com
Mon Mar 21 10:42:08 GMT 2011


On Mon, 21 Mar 2011 11:28:38 +0100, John Beuving <johnbeuving at gmail.com>
wrote:
> Hi,
> 
> I have the following c++ code which I want to sip.
> 
> struct message
> {
>      int id;
>      char username[250];
>      char field[20];
> };
> 
> The sip parser gives a syntax error on the line with the square
brackets.
> What is the best solution to work around this problem?

Array support is on the TODO list.

The easiest workaround is to define a UserName %MappedType that does the
conversion and the necessary bounds checks and define username with the
UserName type. This is all in the .sip file, you don't need to change the
C++ code.

Or you can be a bit more clever and do something like...

template<SIZE>
%MappedType CharArray<SIZE>
{
    ...
};

typedef CharArray<250> UserName;
typedef CharArray<20> Field;

struct message
{
    int id;
    UserName username;
    Field field;
};

...I think.

Phil


More information about the PyQt mailing list