[PyKDE] sip: C++ virtual methods

Patrick Stinson ajole-1 at gci.net
Wed Sep 24 11:26:00 BST 2003


> What do you get when you "print media"? If you get a PK_MediaLayer instance
> then maybe you haven't implemented %ConvertToSubClassCode properly.

I get a PK_MediaLayer instance. Ok, then, that would make sense. I''l check 
that code tag...


> What versions are you using?

ajole at ajole ajole $ sip -V
3.8 (build 109)
ajole at ajole ajole $ python -V
Python 2.3
ajole at ajole ajole $ uic -version
User Interface Compiler for Qt version 3.1.2

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?
>
> Phil
>
> _______________________________________________
> PyKDE mailing list    PyKDE at mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde




More information about the PyQt mailing list