[PyQt] [SIP] sip and template

Phil Thompson phil at riverbankcomputing.com
Thu Feb 24 14:12:34 GMT 2011


On Fri, 11 Feb 2011 14:04:46 +0100, Kermit <stef.kermit at gmail.com> wrote:
> hi,
> 
> since my last post, i've lot difficult to implement a "simple" binding
with
> sip
> 
> i try to bind the good ilmBase librairy.
> i extract a exemple with error with sip
> 
> // ________________________C+++ File ________________________
> #ifndef INCLUDED_IMATHVEC_H
> #define INCLUDED_IMATHVEC_H
> 
> namespace Imath {
> template <class T> class Vec2;
> 
> template <class T> class Vec2
> {
>   public:
> 
>     T x, y;
> 
>     T & operator [] (int i);
>     const T & operator [] (int i) const;
> 
>     Vec2 ();                        // no initialization
>     explicit Vec2 (T a);            // (a a)
>     Vec2 (T a, T b);                // (a b)
> // Base type -- in templates
> typedef T BaseType;
> };
> 
> // Typedefs for convenience
> typedef Vec2 <int>    V2i;
> typedef Vec2 <float>  V2f;
> typedef Vec2 <double> V2d;
> 
> } // namespace Imath
> 
> #endif
> 
> // ________________________Sip  File ________________________
> %Module KitCG 0
> 
> %UnitPostIncludeCode
> namespace Imath {};
> using namespace Imath;
> %End
> 
> template<TYPE>
> class Vec2
> {
> %TypeHeaderCode
> #include "ImathVec.h"
> %End
>   public:
>     TYPE x;
> TYPE y;
> // For info, TYPE x,y;  or mmore simple float x,y; generate a sip error
> 
>     TYPE & operator [] (int i);
>     const TYPE & operator [] (int i) const;
> 
> 
>     //-------------
>     // Constructors
>     //-------------
> 
>     Vec2 ();                        // no initialization
>     explicit Vec2 (TYPE a);            // (a a)
>     Vec2 (TYPE a, TYPE b);                // (a b)
>  // Base type -- in templates
>     typedef TYPE BaseType;
> };
> 
> 
> with this code, i've "sip: TYPE is undefined" error message
> 
> i read qlist.sip, but i understand is a converion between a QList in C++
> and
> python list
> 
> in my case, i want a v2f, v2d python object
> 
> thx for your help
> 
> Kermit

This should now be fixed in hg. The problem is the typedef - maybe you
don't actually need it?

Phil


More information about the PyQt mailing list