a work around for the fact that groups and items are in the same collection, which can cause issues on destruction
BUG:242112 svn path=/trunk/KDE/kdelibs/; revision=1141872
This commit is contained in:
parent
bf60c264ac
commit
0543ed0f15
@ -110,14 +110,30 @@ Extender::Extender(Applet *applet)
|
||||
Extender::~Extender()
|
||||
{
|
||||
d->destroying = true;
|
||||
QMutableListIterator<ExtenderItem *> it(d->attachedExtenderItems);
|
||||
while (it.hasNext()) {
|
||||
ExtenderItem *item = it.next();
|
||||
item->disconnect(this);
|
||||
delete item;
|
||||
|
||||
// when deleting items that are connected to us, it can happen that
|
||||
// other items which are in groups may get deleted as well. so we first
|
||||
// build a new list of guarded pointers, and then use that list. that
|
||||
// way when items are deleted behind our back, we are still safe.
|
||||
// FIXME: having groups and items in the same collection is probably a mistake,
|
||||
// so would be a good candidate for a refactoring exercise
|
||||
QList<QWeakPointer<ExtenderItem> > guardedItems;
|
||||
|
||||
foreach (ExtenderItem *item, d->attachedExtenderItems) {
|
||||
guardedItems << QWeakPointer<ExtenderItem>(item);
|
||||
}
|
||||
|
||||
d->attachedExtenderItems.clear();
|
||||
|
||||
foreach (const QWeakPointer<ExtenderItem> &guardedItem, guardedItems) {
|
||||
ExtenderItem *item = guardedItem.data();
|
||||
if (item) {
|
||||
item->disconnect(this);
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user