[PyKDE] About getting Qt C++ hidden under a PyObject*

Gerard Vermeulen gvermeul at grenoble.cnrs.fr
Tue Oct 7 11:10:01 BST 2003


On Tue, 07 Oct 2003 09:55:32 +0200
Pierre Barbier de Reuille <pierre.barbier at cirad.fr> wrote:

> Le lun 06/10/2003 à 16:51, Gerard Vermeulen a écrit :
> > Hi,
> > 
> > I think so, see my post of last Thursday replying Joe Van Andel.
> > The attached example concerned Vtk Python objects, but I would try
> > the same approach for Boost.
> > 
> > There may be a few gotchas, though:
> > (1) sip generated modules do not use Python's standard way of importing
> >     other modules' C-API's. I solve this by patching sip's output.
> 
> mmmm ... I really don't see what you are calling "patching the sip's
> output".
>
I do not know exactly what means boost provides if you want to use the
C-API (or C++-Api) in other extension modules.

There is a standard Python way to export a C-API to other modules (Numeric,
numarray, pygame, the curses extension in the Python lib do this):
// The Python module initialisation function.

extern "C" SIP_EXPORT void initlibqwtc()
{
        static PyMethodDef methods[] = {
                {"sipCallCtor", callCtor, METH_VARARGS, NULL},
                {"sipCallGetVar", callGetVar, METH_VARARGS, NULL},
                {"sipCallSetVar", callSetVar, METH_VARARGS, NULL},
                {"sipInitModule", initModule, METH_VARARGS, NULL},
                {"sipRegisterClasses", registerClasses, METH_VARARGS, NULL},
                {NULL}
        };

        // Initialise the module.

        Py_InitModule("libqwtc",methods);
#ifdef HAS_NUMERIC
        import_NumericArray();
#endif
#ifdef HAS_NUMARRAY
        import_NumarrayArray();
#endif
}
where I patched the import_XXX statements into sip's code (PyQwt does this
automatically).

On the other hand, my obsolete Vtk stuff does not seem to patch (that means
everything is done by linking -- this works on Intel platforms, but not
on MacOSX, where you cannot mix dynamically loaded modules and shared
libraries. This is the main reason why PyQt does not work on MacOSX).

I really do know nothing about boost intrinsics.  
 
>
> > (2) it is probably impossible to mix the inheritance hierarchies of
> >     sip-generated and boost-generated classes.
> 
> Yes, I think so, and I never intent to mix the inheritance classes ... 
> 
> > 
> > I have a vague recollection of a thread about mixing SIP and Boost.
> > 
> > Gerard
> > 
> > _______________________________________________
> > PyKDE mailing list    PyKDE at mats.imk.fraunhofer.de
> > http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
> 
> I really don't know how to work with your example. So you imply I have
> to re-export the Qt objects ?
>
Oops, my point of view is using boost (or VTK) wrapped objects in sip-files.
> 
> Doing some search in a sip documentation, I found the function
> "sipGetCppPtr". But if I try to call this function directly from my
> non-sip file (a plain C++ file in fact ...) I get a segmentation fault
> inside this function. Here some of my code :
> 
> void a2_fromQImage(  array2d* a, PyObject *obj )
> {
>   sipThisType sipThisInfo;
>   QImage* img = ( QImage* )sipGetCppPtr( &sipThisInfo, obj );
>   if( img != NULL )
>     {
> 	// Do something
>     }
> }
> 
> Do I get something wrong ? Do I need to do some initialisation before
> sipGetCppPtr is called (knowing that PyQt has to be loaded before my
> module can bo loaded !!!)
>
I never thought about this.  I work the other way around and for the moment
I cannot help you.  On the other hand, yesterday evening I started
considering wrapping a 3D plotting library (qwtplot3d.sf.net) and it has
a lot of std - lib template code.  So, I am considering mixing sip and boost.

In a week, I may help you better.

Gerard




More information about the PyQt mailing list