On Sun, 17 Mar 2013 10:10:00 +0100, Vincent Vande Vyvre <[email protected]> wrote: > 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@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 ?
You code just implements a type convertor - %MethodCode does more than that. See... http://pyqt.sourceforge.net/Docs/sip4/directives.html#directive-%MethodCode sipCpp is "this", the Histogram instance. You've defined getHistogram() as returning a double, but you say it returns an array of doubles. You haven't called Histogram::getHistogram(). You have included "return" statements which you must not do. Phil _______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
