[PyKDE] sip: C++ virtual methods
ajole-1 at gci.net
Wed Sep 24 19:08:00 BST 2003
Does the %ConvertToSubClassCode directive require some sort of class
identification mechanism to be written into the original cpp library code?
QEvent returns an enumerated value in type(), as well ass QApplication and
some others, and QObject has QObject::className() that returns a string
identifier. that can be used in conjuction with sipMapStringToClass() and a
Does this mean I have to modify my cpp library to add some sort of class
identifier for classs/subclasses if I want polymorphic return values in my
On Monday 22 September 2003 01:03, Phil Thompson wrote:
> On Monday 22 September 2003 6:11 am, Patrick Stinson wrote:
> > I've been having a never-ending struggle with virtual methods. It seems
> > that virtual methods wrapped by sip don't always work - that is they
> > actually end up working like non-virtual functions. This isn't
> > consistent, and I've never found a solution besides fiddling with it
> > until the _same exact_ code ends up functioning differently after a
> > number of print-out style debugging.
> > Consider this:
> > media = PK.CreateMediaLayer("./track.ogg")
> > while not media.AtEnd():
> > media.Read()
> What do you get when you "print media"? If you get a PK_MediaLayer instance
> then maybe you haven't implemented %ConvertToSubClassCode properly.
> > All of these methods are C++ wrapped methods. PK::CreateMediaLayer()
> > returns a PK_MediaLayer *, which may be an instance of either
> > PK_WaveDecoder or PK_OggDecoder. All PK_Media:Layer methods are [not
> > pure] virtual in sip and C++, are reimplemented in the respective
> > subclasses, are are not inline.
> > In the above example, media.AtEnd() is supposed to call
> > PK_OggDecoder::AtEnd(), but it really calls PK_MediaLayer::AtEnd(). Why
> > is that? Are there certain caveats with C++ virtual functions that I have
> > naively overlooked? What is the relationship to methods declared virtual
> > in sip and those declared virtual in C++? Is virtual really needed in
> > sip?
> Yes, so that code is generated to "catch" the virtual call and check for
> (and execute) any Python reimplementation.
> What versions are you using?
> PyKDE mailing list PyKDE at mats.imk.fraunhofer.de
More information about the PyQt