[PyKDE] PyQt C API

Phil Thompson phil at riverbankcomputing.co.uk
Tue Oct 18 18:02:21 BST 2005


On Tuesday 18 October 2005 5:39 pm, Jim Bublitz wrote:
> On Tuesday 18 October 2005 00:44, Toby Dickenson wrote:
> > I am considering translating a few functions of our large PyQt
> > application to C (or, probably, pyrex) as a performance optimisation, but
> > I have stumbled at the first hurdle. How do you convert a PyObject
> > pointer to a PyQt object into a pointer to the Qt C++ object?
> >
> > Thanks in advance,
>
> Is this what you mean?
>
>     PyObject *elem;   // Points to QRect object type
>     QRect *cpp;
>     int iserr = 0;
>
>     cpp = (QRect *)sipForceConvertTo_QRect (elem, &iserr);
>     if (iserr)
>     {
>         *sipIsErr = 1;
>         return 0;
>     }
>
> The only thing that would change in most cases is substituting the
> particular Qt object type of interest for QRect everywhere. The "sipIsErr"
> is part of %MappedTypeCode - probably won't apply most places.

Or you can use the lower level sipConvertToCpp() which skips some error 
checking.

Phil




More information about the PyQt mailing list