[Qt-qml] QDeclarativeView::setObjectOwnership

Girish Ramakrishnan girish at forwardbias.in
Mon Nov 29 10:38:20 CET 2010


Hi,
QDeclarativeView::setObjectOwnership doesn't seem to be working as I
would expect. Maybe I am reading the documentation wrong.

In essence, I have a
Q_INVOKABLE QObject *create() {
    Object *o = new Object;
    o->setObjectName("object x");
    QDeclarativeEngine::setObjectOwnership(o, QDeclarativeEngine::CppOwnership);
    return o;
}

I call the above function from QML and despite the ownership being set
to CppOwnership, the above objects gets deleted anyway.

If you want full compilable code, it's here -
http://pastebin.com/ffqmxHy6. Keep clicking on the rectangle to create
new objects. Then close the app, all the created objects gets deleted
(I thought setting CppOwnership will make qml not delete the objects).

Girish



More information about the Qt-qml mailing list