[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] lqt 0.9
- From: Michal Kottman <k0mpjut0r@...>
- Date: Tue, 12 Apr 2011 22:45:14 +0200
On 12 April 2011 18:19, Jerome Vuarand <jerome.vuarand@gmail.com> wrote:
> 2011/4/12 Michal Kottman <k0mpjut0r@gmail.com>:
>> It MAY still crash under heavy load, or there may be some API quirks, so
>> any feedback is highly appreciated.
>
> In the documentation, you write that one shouldn't explicitly delete
> an object created by lqt when the object is in a QObject parent/child
> tree. AFAIK this is allowed in C++, the QObject destructor taking care
> of removing the deleted object from its parent child list (and
> deleting its own children). Can you tell us why it's not allowed in
> Lua?
I am sorry if the documentation causes confusion, but I didn't state
that you shouldn't explicitly delete an object created in lqt. Of
course you can delete it, and when the object is derived from QObject,
then all it's children are deleted too.
The problem is with automatic memory collection of objects that Qt can
keep reference to itself. Lua has no way of knowing about those
references, and may choose to delete the object (and possibly break
havoc if Qt tries to access it).
I met with this when I created a model for a QListView and filled it
with items. I created them as new_local() (= use Lua GC), and didn't
keep references to them. After some time (mouse events, scrolling, ...
over the list view), the items started "magically disappearing" - that
is because after Lua deleted the "unreachable" items, they removed
themselves cleanly from the model. However, this "clean behavior"
cannot be guaranteed for all objects, especially for those that do not
inherit from QObject.