Hi,
Replying to myself.
On Mon, Nov 29, 2010 at 3:08 PM, Girish Ramakrishnan
wrote:
> 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).
>
Gregory pointed out on irc that I need to prove that qml is deleting
it. So here's my gdb session:
Creating new Object(0x85c5f0) // Object gets created
3
Breakpoint 1, QObject::deleteLater (this=0x60cf40) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:2123
2123QCoreApplication::postEvent(this, new
QEvent(QEvent::DeferredDelete)); // this is the delete of the view
(gdb) c
Continuing.
Breakpoint 1, QObject::deleteLater (this=0x85c5f0) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:2123
2123QCoreApplication::postEvent(this, new
QEvent(QEvent::DeferredDelete)); // delete of the object (see pointer
value)
(gdb) bt
#0 QObject::deleteLater (this=0x85c5f0) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:2123
#1 0x77a30ff7 in ObjectData::~ObjectData (this=0x85b170,
__in_chrg=)
at
/home/girish/Qt/qt-4.7/src/declarative/qml/qdeclarativeobjectscriptclass.cpp:73
#2 0x77460ac1 in
QScript::DeclarativeObjectDelegate::~DeclarativeObjectDelegate
(this=0x86e7a0, __in_chrg=)
at /home/girish/Qt/qt-4.7/src/script/bridge/qscriptdeclarativeobject.cpp:56
#3 0x7744703e in QScriptObject::Data::~Data (this=0x797a10,
__in_chrg=)
at /home/girish/Qt/qt-4.7/src/script/bridge/qscriptobject.cpp:42
#4 0x774471b4 in QScriptObject::~QScriptObject
(this=0x7fffe13c4d40, __in_chrg=)
at /home/girish/Qt/qt-4.7/src/script/bridge/qscriptobject.cpp:52
#5 0x7734b52e in QTJSC::Heap::freeBlocks (this=0x7fffec046a18)
at
/home/girish/Qt/qt-4.7/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp:349
#6 0x7734af21 in QTJSC::Heap::destroy (this=0x7fffec046a18)
at
/home/girish/Qt/qt-4.7/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp:199
#7 0x7741f7a8 in QScriptEnginePrivate::~QScriptEnginePrivate
(this=0x8025b0, __in_chrg=)
at /home/girish/Qt/qt-4.7/src/script/api/qscriptengine.cpp:1028
#8 0x7520e0aa in QScopedPointerDeleter::cleanup
(pointer=0x8025b0)
at
../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:62
#9 0x7526ede5 in QScopedPointer >::~QScopedPointer (this=0x802098,
__in_chrg=)
at
../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:100
#10 0x752669ab in QObject::~QObject (this=0x802090,
__in_chrg=) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:963
#11 0x77424d38 in QScriptEngine::~QScriptEngine
(this=0x802090, __in_chrg=)
at /home/girish/Qt/qt-4.7/src/script/api/qscriptengine.cpp:1980
#12 0x77956da6 in
QDeclarativeScriptEngine::~QDeclarativeScriptEngine (this=0x802090,
__in_chrg=)
at /home/girish/Qt/qt-4.7/src/declarative/qml/qdeclarativeengine.cpp:382
#13 0x779586a6 in
QDeclarativeEnginePrivate::~QDeclarativeEnginePrivate (this=0x801f80,
__in_chrg=)
at /home/girish/Qt/qt-4.7/src/declarative/qml/qdeclarativeengine.cpp:431
#14 0x7520e0aa in QScopedPointerDeleter::cleanup
(pointer=0x801f80)
at
../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:62
#15 0x7526ede5 in QScopedPointer >::~QScopedPointer (this=0x801388,
__in_chrg=)
at
../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:100
#16 0x752669ab in QObject::~QObject (this=0x801380,
__in_chrg=) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:963
#17 0x77958ed1 in QDeclarativeEngine::~QDeclarativeEngine
(this=0x801380, __in_chrg=)
at /home/girish/Qt/qt-4.7/src/declarative/qml/qdeclarativeengine.cpp:555
#18 0x77839804 in
QDeclarativeViewPrivate::~QDeclarativeViewPrivate (this=0x7ed250,
__in_chrg=)
at /home/girish/Qt/qt-4.7/src/declarative/util/qdeclarativeview.cpp:135
#19 0x7520e0aa in QScopedPointerDeleter::cleanup
(pointer=0x7ed250)
at
../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:62
#20 0x7526ede5 in QScopedPointer >::~QScopedPointer (this=0x60cf48,
__in_chrg=)
---Type to continue, or q to quit---
at
../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:100
#21 0x75266