[PyKDE] Using SIP to wrap python objects
Phil Thompson
phil at riverbankcomputing.co.uk
Fri Jun 13 12:50:00 BST 2003
On Friday 13 June 2003 11:27 am, Rob Knapp wrote:
> On Friday 13 June 2003 04:21 am, Phil Thompson wrote:
> > On Friday 13 June 2003 12:31 am, Rob Knapp wrote:
> > > I've found myself in a position where I need to present a python object
> > > to a C++ object, and it needs to look like a C++ object. The target
> > > application knows nothing of python.
> >
> > What C++ object does it need to look like?
>
> It needs to be a QObject, more specifically we want it to inherit from
> QWidget ...which is why SIP looks like such a good match.
>
> > > Would it be possible to create an object using SIP that I can inherit
> > > from and use the SIP api to convert into a CppPointer?
> >
> > If you have a C++ ctor for the object then that's exactly what SIP does,
> > so maybe what you want to do is more complicated than your are implying?
>
> So, if I inherit a C++ object from QWidget and write a sip binding, then
> I'm set. That's what I thought, but what I was hoping for was some way to
> automatically generate this "in between" object.
It can't be automatically generated if you are adding functionality (the new
methods and slots) to it.
> Here is what I'm trying to do:
>
> Let's say I need to add some slots to QWidget and a couple of methods, I
> then need to embed this on a dialog box made by someone else in C++. That
> dialog box needs access to these additional methods and slots.
>
> From what I'm seeing in the responses, I would write a C++ class(QMyddrin)
> that inherits from QWidget and adds these methods. Then my python ocde I
> would inherit from QMyddrin and it should all work as long as I do the
> conversion from Py_Object to CppPointer (I forget the call name.)
Yes - but where are you going to put the code that does that conversion? Does
the dialog include a method that will embed your QMyddrin instance?
> That may be enough becuase I can probably modify some existing python
> introspection code that I have to spit out the .h, .cpp and .sip files
> fairly easily.
Phil
More information about the PyQt
mailing list