Is it bad to delete an object during its event handler?
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):
Code:
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
Re: Is it bad to delete an object during its event handler?
Re: Is it bad to delete an object during its event handler?
Hmm thanks... except how I clear my form is using this:
Code:
QObjectList childrenList = children();
childrenList.removeAt(childrenList.indexOf(DoNotDeleteMeObject));
...
qDeleteAll(childrenList);
Is there an alternative for qDeleteAll() which uses deleteLater()?
Re: Is it bad to delete an object during its event handler?
Quote:
Originally Posted by
codeslicer
Is there an alternative for qDeleteAll() which uses deleteLater()?
Code:
foreach
(QObject* child, childrenList
) child->deleteLater();