[PyKDE] SIP automatically casting up to a QWidget
Giovanni Bajo
rasky at develer.com
Thu Feb 22 14:32:23 GMT 2007
On 2/22/2007 2:53 PM, Paul Giannaros wrote:
> I have a class A that i'm wrapping with SIP. The class inherits from a bunch
> of other classes. One of the classes it inherits from also in turn inherits
> from QWidget. When I import the created module, whenever I call a method that
> is meant to return an instance of class A I get a QWidget instead. I can use
> sip.cast to get the QWidget back to an A instance, but that's not a very
> friendly solution.
> Can someone suggest why this is happening, or how to fix it?
SIP needs to know the correct run-time type of your class: otherwise
when it receives a QWidget* it cannot know what type the class really is.
Have a look at how %ConvertToSubClassCode is implemented in
QtCore/qobject.sip and QtGui/qapplication.sip (assuming you're using
Qt4). Within your a.sip, you must add your own %ConvertToSubClassCode
that verifies if a generic QObject* is an instance of your type (class
A). SIP then knows how to "chain" all the other %ConvertToSubClassCode
in the object hierarchy, so your code needs only to verify your own class.
--
Giovanni Bajo
More information about the PyQt
mailing list