[PyKDE] Sip does not wrap static const members of mapped type?

Jacob M. Burbach jacobb at cfl.rr.com
Tue Apr 18 05:14:20 BST 2006

I'm wrapping some classes and find that Sip will not wrap static const members 
that are defined as a MappedType. Standard types, wrapped types, and
non const members are wrapped ok, just not const mapped types. This seems like 
a bug in sip?

As a work around I can remove the  'const' and provide hand written code to do 
the conversions and it will work. I have hundreds of such members though so 
that is less than ideal for me. 

//--- Example module --//
%Module Test 0

// Map std string
%MappedType std::string
#include <string>

if (sipIsErr == 0)
    return PyString_Check(sipPy);

*sipCppPtr = new std::string( PyString_AsString(sipPy) );
return sipGetState(sipTransferObj);

return PyString_FromString( sipCpp->c_str() );

// Define two class to wrap

#include <string>
class NotAMappedType {
    NotAMappedType() {}

class Test {
    static const std::string StringOne;
    static const std::string StringTwo;
    static const NotAMappedType NonMappedType;
    static const double MyDouble;
    static const int MyInt;

const std::string Test::StringOne = "StringOne";
const std::string Test::StringTwo = "StringTwo";
const NotAMappedType Test::NonMappedType;
const double Test::MyDouble = 102.021;
const int Test::MyInt = 32;

// Wrapper specs

class NotAMappedType

class Test
    static const std::string StringOne; // Sip will not wrap.
    //static const std::string StringTwo;
    static std::string StringTwo; // Work around
     sipPy = 
sipMappedType_std_string, 0);
    sipErr = 1;
    PyErr_SetString(PyExc_AttributeError, "Read only member");

    static const int MyInt; // Ok 
    static const double MyDouble; Ok
    static const NotAMappedType NonMappedType; // Ok

More information about the PyQt mailing list