Solved QDeleteAll issue with QMap<QString,QObject *>
-
Hello, I'm working on a QML API.
I call QDeleteAll in order to delete my list of Objects stored in QMap<QString, CanMessage*>. CanMessage inherits QObject.
when i call the qDeleteAll my application crash.
Can anyone help,pls? -
@Babs said in QDeleteAll issue with QMap<QString,QObject *>:
when i call the qDeleteAll my application crash.
Run your Debugger. What does your Stack Trace show when it crashes?
You might need to call
QObject::deleteLater()
instead of deleting them directly. -
@JKSH deleteLater() is not working either. It provoke a segmentation fault
-
@Babs said in QDeleteAll issue with QMap<QString,QObject *>:
when i call the qDeleteAll my application crash.
Are you sure your
QMap
is correctly initialized? All values are valid? No dangling pointers?As you are saying CanMessage inherits from
QObject
, I would suggest you to useQPointer
and change your type declaration toQMap<QString , QPointer<CanMessage> >
, this should avoid to have duplicated deallocation. -
@KroMignon thank you. I used QPointer and it works properly.
-
Hi,
Then post the stack trace corresponding to your crash.