Unfortunately, QtScript seems to be getting in the way.
The approved way to remove widgets is like so in C++:
Code: Select all
QLayoutItem *child;
while ((child = layout->takeAt(0)) != 0) {
...
delete child;
}
Code: Select all
QLayoutItem* item;
while ( !items_.isEmpty() && ( (item = items_.takeFirst()) != 0 ) ){
layout()->removeWidget(item);
delete item; // It works no matter where the item is
}
items_.clear(); // clear the list afterwards.
The problem is that this doesn't translate well to QtScript:
Code: Select all
var rootLayout = this.widget.layout();
debugger;
this.widgets.forEach(function (gb) {
rootLayout.removeWidget(gb);
delete gb;
});
this.widgets = [];
I then tried removing the layout, but that is not possible because of the QSharedPointer being maintained by QtScript.
Code: Select all
var rootLayout = this.widget.layout();
delete rootLayout;
rootLayout = new QVBoxLayout();
this.widget.setLayout(rootLayout); // error Layout still set
So I'm at a loss as to how to replace widgets inside a single widget if I can't delete the Widget's layout like Qt expects..