[PyQt] Returning a QImage instance from SIP

Jeremy Sanders jeremy at jeremysanders.net
Mon Aug 16 11:38:06 BST 2010


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?

Thanks

Jeremy

-- 
http://www.jeremysanders.net/



More information about the PyQt mailing list