[PyQt] sip: wrong class virtual function being called

Jeremy Sanders jeremy at jeremysanders.net
Fri Jun 5 18:34:46 BST 2015


Hi -

I'm having a problem with sip where the wrong version of a virtual 
function is being called. I'm overriding a virtual function in a python 
subclass of a C++ class. This function is being called by a C++ 
container, which owns the class instance. If I keep a Python reference 
to the instance, then everything works.

Please see the attached code. test.py calls the C++ code. Normally the 
code prints

Object::func()
42

If del in test.py is uncommented, then it prints

Object::func()
Object::func()

Therefore the inherited virtual function is being called, not the 
overriding function.

Is this a problem with my code, or a SIP bug? I'm using SIP 4.16.3 (on 
Ubuntu x86-64). Is there a workaround? I can change the C++ code.

Thanks

Jeremy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.py
Type: text/x-python
Size: 278 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150605/1792d355/attachment.py>
-------------- next part --------------
%Module(name=mytest, version=0)

class Object
{
%TypeHeaderCode
#include <mytest.h>
%End
  public:
   virtual ~Object();
   virtual void func();
};

class ObjectContainer : public Object
{
%TypeHeaderCode
#include <mytest.h>
%End
 public:
  ~ObjectContainer();
  void addObject(Object* obj /Transfer/);
  void callFuncs();
};

class Scene
{
%TypeHeaderCode
#include <mytest.h>
%End

 public:
  Scene();
  ObjectContainer root;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mytest.cpp
Type: text/x-c++src
Size: 433 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150605/1792d355/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mytest.h
Type: text/x-chdr
Size: 367 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150605/1792d355/attachment.h>


More information about the PyQt mailing list