[PyQt] Returning a QImage instance from SIP
Phil Thompson
phil at riverbankcomputing.com
Mon Aug 16 12:34:49 BST 2010
On Mon, 16 Aug 2010 11:38:06 +0100, Jeremy Sanders
<jeremy at jeremysanders.net> wrote:
> Hello - is this the correct way to return a QImage from a SIP
MethodCode?
>
> QImage numpyToQImage(SIP_PYOBJECT, SIP_PYOBJECT, bool forcetrans =
false);
> %MethodCode
> {
> try
> {
> Numpy2DObj data(a0);
> Numpy2DIntObj colors(a1);
> QImage *img = new QImage( numpyToQImage(data, colors, a2) );
> sipRes = img;
> }
> catch( const char *msg )
> {
> sipIsErr = 1; PyErr_SetString(PyExc_TypeError, msg);
> }
> }
> %End
>
> numpyToQImage returns a QImage.
>
> It seems to work, but is there a memory leak? Should I be transferring
> ownership here?
No - it's correct as it is.
Phil
More information about the PyQt
mailing list