[PyKDE] More SIP questions

Jim Bublitz jbublitz at nwinternet.com
Wed Mar 26 01:27:01 GMT 2003


On 25-Mar-03 WELCH,DONALD J (HP-Vancouver,ex1) wrote:
> Thanks again for the quick response to my earlier queries. I have
> an additional point of contention:
  
> Each of these 5 variables and methods in the class are causing me
> grief.

I'm guessing at some of these, but on the off chance Phil doesn't
respond, here's what I'd try:
  
> // channel.h
> class Channel 
> {
>     public:
>         static const int MAX_LEN = 4096;

    int MAX_LEN;

I don't think sip will handle the 'static'. The initialization
should take place in the C++ code (lib), so you shouldn't need to
specify it (and I don't believe sip will let you). 

>         static const char DEF_NAME[] = "UNKNOWN";

    char *DEF_NAME;

Same - I don't believe sip handles [] (directly).

    
>         Channel & operator=( const Channel & chan );

sip doesn't presently handle operators - might be able to do it in
Python somehow (and embed the code in the sip file); not sure. 
  
>         virtual ~Channel();

Delete it (if it's public).  If it's private, leave it in but drop
the 'virtual'. If it's protected (guessing) make it private (and
still drop the 'virtual').

>         static void delay( struct timeval value);

'struct timeval' needs a declaration somewhere in the module. I
believe sip handles 'struct' now, but I still convert everything to
classes:

   class timeval
   {
   %HeaderCode 
   #include <??>
   %End
    
   public:   // a C++ struct is a class whose default access is
             // public
      ...
   };

   static void delay (timeval);

Note that for methods, 'static' is critical (it indicates that no
'this' pointer is passed in the method call). 'timeval' can be
nested within Channel if that's where the struct is in the h file -
in that case, drop the %HeaderCode block (only use it if the class
declaration occurs outside a class scope - in a namespace or
global). If it's declared inside a different class (or in any named
namespace, including the current namespace), it will have to be
scoped: OtherClass::timeval or SomeNameSpace::timeval.

Same thing exactly for:

typedef struct {...} timeval;

That's still a class declaration - it just looks funny.

Lastly, the 'const' in the first two lines might cause some
compiler problems if omitted - not sure, but I'd try it without
first.


Jim




More information about the PyQt mailing list