[PyKDE] Filling QPixmap from C code
Phil Thompson
phil at river-bank.demon.co.uk
Wed Apr 16 10:03:01 BST 2003
On Wednesday 16 April 2003 8:23 am, Giaco777 wrote:
> Hi PyQters,
>
> first of all I would like to thank Phil for this great RAD environment
> for QT.
>
> In my application I would like a QPixmap generated by PYQt
> to be filled by a C subroutine. My first try would look like this (in
> principal):
>
> Python:
>
> qp=QPixmap(...)
> fillQPixmap(qp) # this is realized in C
>
> C:
>
> // this is the C subroutine which fills QPixmap
> static PyObject *fillQPixmap(PyObject *self, PyObject *args) {
> PyObject * po;
> if(!PyArg_ParseTuple(args, "O", &po)) return NULL;
>
> // interpret object as QPixmap pointer
> QPixmap *pm = (QPixmap*) PyCObject_AsVoidPtr(po);
>
> // do something with pm
>
> Py_INCREF(Py_None);
> return Py_None;
> }
>
>
> Is there a chance that this will work or is there a better solution?
There is no chance that this will work because po is a class instance and the
real C++ pointer is buried deep within in.
You need something like...
// interpret object as QPixmap pointer
int iserr = FALSE;
QPixmap *pm = (QPixmap *)sipConvertToCpp(po,sipClass_QPixmap,&iserr);
if (iserr)
return NULL;
if (pm == NULL)
{
raise_exception_about_None_being_passed();
return NULL;
}
Phil
More information about the PyQt
mailing list