[PyKDE] SIP: wrapper code calls virtual functions with base class prefix

Phil Thompson phil at riverbankcomputing.co.uk
Wed Jul 9 12:19:00 BST 2003


On Tuesday 08 July 2003 12:49 pm, Tore Knabe wrote:
> Hi,
>
> I want to wrap a base class, which serves as an
> interface, and inherit from this base class in C++.
> The C++ class, which is not wrapped, overrides the
> virtual function foo() from the base class. My
> problem: when I call a factory method in Python to
> create an object obj of the derived class, then
> calling obj.foo() in Python executes the code from the
> base class, not the derived one. Looking at the
> wrapper code generated by SIP shows that foo is called
> with the base class scope: BaseClass::foo(). This code
> is generated by the function generateFunctionCall in
> the SIP source file gencode.C. The commentary to the
> function says:
>
> "... call the real function and not any version in the
> wrapper class in case it is virtual.  This will
> prevent virtual loops."
>
> This protection against virtual loops prevents me from
> using an interface class the way I planned. What would
> happen if it were removed? What is an example of a
> virtual loop?

class MyWidget(QWidget):
    def setPalette(self,p):
        # Do some fiddling with the palette.
        # Now call the base class implementation.
        QWidget.setPalette(self,p)

Phil




More information about the PyQt mailing list