[PyQt] VirtualCatcherCode and abstract methods

James Emerton ephelon at gmail.com
Sat May 12 02:26:11 BST 2007


I have an interface declaring some abstract methods:

class IUnknown
{
public:
  virtual int AddRef() = 0;
  virtual int Release() = 0;
};

When I am implementing that interface in Python, I don't want to be
bothered with the mechanics of reference counting, so I abuse Python's
own ref count.  (I believe that this should work in principle, but I
still lack proof.)

Hence, the use of %VirtualCatcherCode:

virtual int AddRef() = 0;
%VirtualCatcherCode
  PyObject* self = PyMethod_Self(sipMethod);
  if( self )
    Py_INCREF( self );
%End

Along with a very similar implementation for Release()

With the above implementation, SIP complains about AddRef() being
abstract and unimplemented.  (It searches for the Python method to
pass as sipMethod, which it cannot find.)

The alternative is to remove the pure virtual notation from the
methods, which results in a compile error in the generated derived
class because it is not legal to call IUnknown::AddRef() with scoping
because the method does not exist!

Any suggestions?


More information about the PyQt mailing list