PDA

View Full Version : Is it bad to delete an object during its event handler?



codeslicer
30th December 2008, 00:49
Hi,

I have a function in which my application changes skins, and where it is necessary to use qDeleteAll() and remove all objects, then make new ones. The object that triggers this function is a button, say Button1. When the button is pressed I get the following error (Qt Creator):


app-stderr:QObject: Do not delete object, 'Button1', during its event handler!

I haven't experienced any Seg faults or other consequences but would like to know if this is in any way dangerous and if it is, how I can avoid it.

Thanks in advance,
codeslicer

jpn
30th December 2008, 07:09
See QObject::deleteLater().

codeslicer
30th December 2008, 15:51
Hmm thanks... except how I clear my form is using this:


QObjectList childrenList = children();
childrenList.removeAt(childrenList.indexOf(DoNotDe leteMeObject));
...
qDeleteAll(childrenList);

Is there an alternative for qDeleteAll() which uses deleteLater()?

jpn
30th December 2008, 16:14
Is there an alternative for qDeleteAll() which uses deleteLater()?


foreach (QObject* child, childrenList)
child->deleteLater();