[Qtscript-bindings] QTreeWidget, deleting/removing an item

Jostein Topland josteint at sim.no
Fri Sep 19 15:45:10 CEST 2008


Try this instead

x = new QWidget();
delete x;
gc(); // force garbage collection, may not be necessary
print(x); // not defined

Stephan Beal wrote:
> On Fri, Sep 19, 2008 at 2:53 PM, Jostein Topland <josteint at sim.no> wrote:
>   
>> 15  delete treeWidget.selectedItems()[0];
>>     
>
> The delete operator in JS is unfortunately an unreliable creature. i
> have seen, e.g.:
>
> var x = new QWidget();
> ...
> delete x;
> print(x); // "QWidget", or similar
>
> IMO print(x) should print "null". i don't know if this is JS behaviour
> in general or specific to the QtScript engine, however.
>
> Another thing i have seen when running scripts from inside an app:
>
> var x = new QWidget();
> ...
> x.deleteLater();
> ...
>
> The native func will not be deleted until deleteLater() is safe (after
> the event queue finished, if i'm not mistaken). If you run the JS
> script in response to some event (e.g. double-click in my case) no
> objects destroyed that way will be destroyed until after the script is
> finished. e.g. i have a game in which i'd like to create and destroy
> pieces from script. i can create them fine, but when i destroy them
> they don't actually go away until the script is finished (which isn't
> terribly helpful in some cases).
>
> Anyway... just a small tip.
>
>   



More information about the Qtscript-bindings mailing list