[Qt-qml] QDeclarativeView::setObjectOwnership
Girish Ramakrishnan
girish at forwardbias.in
Mon Nov 29 10:56:41 CET 2010
Hi,
Replying to myself.
On Mon, Nov 29, 2010 at 3:08 PM, Girish Ramakrishnan
<girish at forwardbias.in> 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
2123 QCoreApplication::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
2123 QCoreApplication::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 0x00007ffff7a30ff7 in ObjectData::~ObjectData (this=0x85b170,
__in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/declarative/qml/qdeclarativeobjectscriptclass.cpp:73
#2 0x00007ffff7460ac1 in
QScript::DeclarativeObjectDelegate::~DeclarativeObjectDelegate
(this=0x86e7a0, __in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/script/bridge/qscriptdeclarativeobject.cpp:56
#3 0x00007ffff744703e in QScriptObject::Data::~Data (this=0x797a10,
__in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/script/bridge/qscriptobject.cpp:42
#4 0x00007ffff74471b4 in QScriptObject::~QScriptObject
(this=0x7fffe13c4d40, __in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/script/bridge/qscriptobject.cpp:52
#5 0x00007ffff734b52e in QTJSC::Heap::freeBlocks (this=0x7fffec046a18)
at /home/girish/Qt/qt-4.7/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp:349
#6 0x00007ffff734af21 in QTJSC::Heap::destroy (this=0x7fffec046a18)
at /home/girish/Qt/qt-4.7/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp:199
#7 0x00007ffff741f7a8 in QScriptEnginePrivate::~QScriptEnginePrivate
(this=0x8025b0, __in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/script/api/qscriptengine.cpp:1028
#8 0x00007ffff520e0aa in QScopedPointerDeleter<QObjectData>::cleanup
(pointer=0x8025b0)
at ../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:62
#9 0x00007ffff526ede5 in QScopedPointer<QObjectData,
QScopedPointerDeleter<QObjectData> >::~QScopedPointer (this=0x802098,
__in_chrg=<value optimized out>)
at ../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:100
#10 0x00007ffff52669ab in QObject::~QObject (this=0x802090,
__in_chrg=<value optimized out>) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:963
#11 0x00007ffff7424d38 in QScriptEngine::~QScriptEngine
(this=0x802090, __in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/script/api/qscriptengine.cpp:1980
#12 0x00007ffff7956da6 in
QDeclarativeScriptEngine::~QDeclarativeScriptEngine (this=0x802090,
__in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/declarative/qml/qdeclarativeengine.cpp:382
#13 0x00007ffff79586a6 in
QDeclarativeEnginePrivate::~QDeclarativeEnginePrivate (this=0x801f80,
__in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/declarative/qml/qdeclarativeengine.cpp:431
#14 0x00007ffff520e0aa in QScopedPointerDeleter<QObjectData>::cleanup
(pointer=0x801f80)
at ../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:62
#15 0x00007ffff526ede5 in QScopedPointer<QObjectData,
QScopedPointerDeleter<QObjectData> >::~QScopedPointer (this=0x801388,
__in_chrg=<value optimized out>)
at ../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:100
#16 0x00007ffff52669ab in QObject::~QObject (this=0x801380,
__in_chrg=<value optimized out>) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:963
#17 0x00007ffff7958ed1 in QDeclarativeEngine::~QDeclarativeEngine
(this=0x801380, __in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/declarative/qml/qdeclarativeengine.cpp:555
#18 0x00007ffff7839804 in
QDeclarativeViewPrivate::~QDeclarativeViewPrivate (this=0x7ed250,
__in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/declarative/util/qdeclarativeview.cpp:135
#19 0x00007ffff520e0aa in QScopedPointerDeleter<QObjectData>::cleanup
(pointer=0x7ed250)
at ../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:62
#20 0x00007ffff526ede5 in QScopedPointer<QObjectData,
QScopedPointerDeleter<QObjectData> >::~QScopedPointer (this=0x60cf48,
__in_chrg=<value optimized out>)
---Type <return> to continue, or q <return> to quit---
at ../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:100
#21 0x00007ffff52669ab in QObject::~QObject (this=0x60cf40,
__in_chrg=<value optimized out>) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:963
#22 0x00007ffff5878184 in QWidget::~QWidget (this=0x60cf40,
__in_chrg=<value optimized out>) at
/home/girish/Qt/qt-4.7/src/gui/kernel/qwidget.cpp:1620
#23 0x00007ffff5d938a8 in QFrame::~QFrame (this=0x60cf40,
__in_chrg=<value optimized out>) at
/home/girish/Qt/qt-4.7/src/gui/widgets/qframe.cpp:242
#24 0x00007ffff5e4ed51 in QAbstractScrollArea::~QAbstractScrollArea
(this=0x60cf40, __in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/gui/widgets/qabstractscrollarea.cpp:526
#25 0x00007ffff6077d9b in QGraphicsView::~QGraphicsView
(this=0x60cf40, __in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/gui/graphicsview/qgraphicsview.cpp:1165
#26 0x00007ffff78363de in QDeclarativeView::~QDeclarativeView
(this=0x60cf40, __in_chrg=<value optimized out>)
at /home/girish/Qt/qt-4.7/src/declarative/util/qdeclarativeview.cpp:300
#27 0x00007ffff526db5b in qDeleteInEventHandler (o=0x60cf40) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:3980
#28 0x00007ffff5267ab7 in QObject::event (this=0x60cf40, e=0x8332d0)
at /home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:1194
#29 0x00007ffff588cbed in QWidget::event (this=0x60cf40,
event=0x8332d0) at
/home/girish/Qt/qt-4.7/src/gui/kernel/qwidget.cpp:8659
#30 0x00007ffff5d94517 in QFrame::event (this=0x60cf40, e=0x8332d0) at
/home/girish/Qt/qt-4.7/src/gui/widgets/qframe.cpp:557
#31 0x00007ffff5e500f8 in QAbstractScrollArea::event (this=0x60cf40,
e=0x8332d0) at /home/girish/Qt/qt-4.7/src/gui/widgets/qabstractscrollarea.cpp:996
#32 0x00007ffff607d0de in QGraphicsView::event (this=0x60cf40,
event=0x8332d0) at
/home/girish/Qt/qt-4.7/src/gui/graphicsview/qgraphicsview.cpp:2741
#33 0x00007ffff581560e in QApplicationPrivate::notify_helper
(this=0x607d20, receiver=0x60cf40, e=0x8332d0)
at /home/girish/Qt/qt-4.7/src/gui/kernel/qapplication.cpp:4445
#34 0x00007ffff5815466 in QApplication::notify (this=0x7fffffffdfb0,
receiver=0x60cf40, e=0x8332d0)
at /home/girish/Qt/qt-4.7/src/gui/kernel/qapplication.cpp:4410
#35 0x00007ffff524c626 in QCoreApplication::notifyInternal
(this=0x7fffffffdfb0, receiver=0x60cf40, event=0x8332d0)
at /home/girish/Qt/qt-4.7/src/corelib/kernel/qcoreapplication.cpp:732
#36 0x00007ffff78cf4d5 in QCoreApplication::sendEvent
(receiver=0x60cf40, event=0x8332d0)
at ../../include/QtCore/../../../../qt-4.7/src/corelib/kernel/qcoreapplication.h:215
#37 0x00007ffff524d875 in QCoreApplicationPrivate::sendPostedEvents
(receiver=0x0, event_type=0, data=0x607ee0)
at /home/girish/Qt/qt-4.7/src/corelib/kernel/qcoreapplication.cpp:1373
#38 0x00007ffff524d495 in QCoreApplication::sendPostedEvents
(receiver=0x0, event_type=0)
at /home/girish/Qt/qt-4.7/src/corelib/kernel/qcoreapplication.cpp:1266
#39 0x00007ffff58f71e5 in QCoreApplication::sendPostedEvents () at
../../include/QtCore/../../../../qt-4.7/src/corelib/kernel/qcoreapplication.h:220
#40 0x00007ffff528a79d in postEventSourceDispatch (s=0x60bd60) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qeventdispatcher_glib.cpp:277
#41 0x00007ffff2c69342 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#42 0x00007ffff2c6d2a8 in ?? () from /lib/libglib-2.0.so.0
#43 0x00007ffff2c6d45c in g_main_context_iteration () from /lib/libglib-2.0.so.0
#44 0x00007ffff528ba93 in QEventDispatcherGlib::processEvents
(this=0x6092c0, flags=...)
at /home/girish/Qt/qt-4.7/src/corelib/kernel/qeventdispatcher_glib.cpp:415
#45 0x00007ffff5904a98 in QGuiEventDispatcherGlib::processEvents
(this=0x6092c0, flags=...)
at /home/girish/Qt/qt-4.7/src/gui/kernel/qguieventdispatcher_glib.cpp:204
#46 0x00007ffff5249648 in QEventLoop::processEvents
(this=0x7fffffffdf40, flags=...) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qeventloop.cpp:149
---Type <return> to continue, or q <return> to quit---
#47 0x00007ffff524979e in QEventLoop::exec (this=0x7fffffffdf40,
flags=...) at /home/girish/Qt/qt-4.7/src/corelib/kernel/qeventloop.cpp:201
#48 0x00007ffff524cd22 in QCoreApplication::exec () at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qcoreapplication.cpp:1009
#49 0x00007ffff58126e8 in QApplication::exec () at
/home/girish/Qt/qt-4.7/src/gui/kernel/qapplication.cpp:3719
#50 0x0000000000401ef5 in main (argc=1, argv=0x7fffffffe118) at main.cpp:50
More information about the Qt-qml
mailing list