[PyKDE] pointer to underlying C++ object?

Mark Phillips mbp at geomtech.com
Wed Sep 4 02:24:00 BST 2002


> Using SIP to create the wrapper for foo() should allow you to do exactly
> want to want. You shouldn't have got "similar problems".

Oops.  Sorry for my confusion.  I actually did have some problems
getting it to work with sip, but I guess they weren't so "similar".

Anyway, inspired by your encouragement I've spent a lot more time with
sip now and have made some progress.  I discovered '%Import qtmod.sip'
which seems to be what's needed to get sip to know about existing Qt
classes, and my sip function wrapper now correctly builds and runs.

However, it turns out that what I'm actually trying to do is more
complicated, and I'm still stuck on something.  The purpose of the
function I'm wrapping is to move pixels from a gdImage object (from
the 'gd' graphics library) into a QImage object so that it can be
rendered in a Qt application window:

   void gdImageToQImage(QImage *im, gdImage *gd)

I've written this function in C++, tested it from a C++ program, and
it works fine.  I'm trying to wrap it so that I can write the
application in python with PyQt, rather than in C++.

Now that I understand how to deal with the QImage* argument, I've moved
on to the gdImage* argument, which is more challenging.  In python,
the gdImage object that I want to pass to this function corresponds to
a swig-wrapped object, rather than a sip-wrapped one.  I guess I can't
teach sip about gdImage by '%Import'ing its sip module, because there
isn't one.  Is there some way I can tell sip enough about an object
wrapped by swig to allow it to correctly deal with a pointer to that
object?  I tried simply putting

   class gdImage {
   public:
     gdImage();
   };

in my sip file, but I still get

   TypeError: Argument 2 of gdImageToQImage() has an invalid type

at runtime.

Or, perhaps this isn't a sip issue. Perhaps there's some way I can
tell python to pass a pointer to the underlying C++ object to my
function, and just declare the function to take a void * argument.
But as I said, I'm new to much of this, and I haven't yet figured out
if that's possible, or how.

Maybe there's even a more straightforward way to get pixels from a
gdImage object into something that I can render in Qt, eliminating the
need for a custom function altogether???

Thanks in advance for any help!

--Mark

Mark Phillips @ Geometry Technologies, LLC
P.O. Box 1170, Black Mountain, NC  28711
Phone: 828-664-1748
mbp at geomtech.com       http://www.geomtech.com




More information about the PyQt mailing list