[PyQt] Question about ownership

Boudewijn Rempt boud at valdyas.org
Sat Dec 17 10:24:47 GMT 2016


I'm writing a wrapper library in C++ around the complex internals of
Krita, and then wrap that library with sip. What I'm not understanding
is when something is owned by Python and will be deleted if the refcount
drops to zero.

For example:

class Document {
    virtual ~/Document() { qDebug() << "destructor called"; }
private:
    // wraps a krita internal object
    KisDocument *document;

}

class Krita {
    Document *createDocument() { return new Document(...); }
    Krita *instance();
};


I expected the following script to call Document's destructor:

document = Krita.instance().createDocument()
...
document = Krita.instance().createDocument()

Because the first instance of document goes out of scope when the
the second instance is created. That doesn't happen, and that means
that I don't understand something here... Is there a way to get sip
to signal that the return value of the wrapped createDocument method
is owned by Python? I thought that sipTransferBack could help here, 
but I cannot figure out how to add that to the Krita.sip file :-(


-- 
Boudewijn Rempt | http://www.krita.org, http://www.valdyas.org


More information about the PyQt mailing list