[PyQt] SIP Error with a %MethodCode

Vincent Vande Vyvre vincent.vandevyvre at swing.be
Sun Mar 17 09:10:00 GMT 2013


Hi,

I have, in C++, a method wich return an array of double and I've set a 
MethodCode in the .sip file to convert the array to a Python list of int.

The array in the C++ code:

---------------------------------
double lr[256];

for (int i = 0 ; i < 256 ; i++)
{
float val = cvRound(b_hist.at<float>(i));
lr[i] = val;
}

return *lr;
---------------------------------

The .sip file:

-----------------------------------------
%Module histogram

class Histogram {

%TypeHeaderCode
#include <histogram.h>
%End


public:
int loadImage(char*) ;
double getHistogram() ;
%MethodCode
PyObject *l ;
int size = 256 ;
// Create the Python list of the correct length.
if ((l = PyList_New(size)) == NULL)
return NULL;

// Go through each element in the C++ instance and convert it to a
// wrapped object.
for (int i = 0; i < size; ++i)
{
// Add the wrapper to the list.
PyList_SET_ITEM(l, i, PyFloat_FromDouble(sipCpp -> at(i)));
}

return l;
%End
};
---------------------------------------

The error when I execute make:

vincent at djoliba:~/oqapy-2/C++/exemples/2$ make
g++ -c -O2 -g -fPIC -Wall -W -DNDEBUG -I. -I/usr/include/python2.7 -o 
siphistogramcmodule.o siphistogramcmodule.cpp
g++ -c -O2 -g -fPIC -Wall -W -DNDEBUG -I. -I/usr/include/python2.7 -o 
siphistogramHistogram.o siphistogramHistogram.cpp
histogram.sip: In function ‘PyObject* 
meth_Histogram_getHistogram(PyObject*, PyObject*)’:
histogram.sip:28:9: erreur: ‘class Histogram’ has no member named ‘at’
make: *** [siphistogramHistogram.o] Erreur 1

In this context, what represent 'sipCpp'? The returned value ?

Thanks


More information about the PyQt mailing list