[PyQt] SIP: how to transfer ownerships

Martin Dobias wonder.sk at gmail.com
Fri Oct 12 01:56:10 BST 2007


I'm trying to find out how to wrap one class but I'm not sure how to
do it correctly...

I have a class which owns a geometry class. The geometry can be at
some point of time detached from the class (and deleted elsewhere):

class Feature
  // returns only reference
  Geometry* getGeometry() { return geom; }
  // marks that it's not responsible for geometry's deletion anymore
  Geometry* getGeometryAndOwnership() { ownsGeometry = 0; return geom; }
  // deletes the geometry if it's still owning it
  ~Feature() { if (ownsGeometry) delete geom; }
  bool ownsGeometry;
  Geometry* geom;

My question is - what annotations should I use for the getter
functions? I guess I should use TransferBack for
getGeometryAndOwnership() as it takes the responsibility for deletion.
But what about getGeometry() ? When used without any annotation I have
a problem in this scenario:
1. feature is created
2. getGeometry is called and the reference is stored
3. feature is deleted
4. reference in python still exists but the object is deleted already...


More information about the PyQt mailing list