Solved Detected QWeakPointer creation in a QObject being deleted
-
Detected QWeakPointer creation in a QObject being deleted
i got this and my app crash when i try to delete one of my created objects
what should i do?
-
Hi,
The description is pretty unclear.
Can you show the related code ?
-
that's some big project!
i try to delete one of my objects but app crashes and i get mentioned error.
the object is inherited from QWidget and have some private objects in it.
i had some memory leak and i am trying to clear them now -
@mahd96 Try to call widget->deleteLater() instead of directly deleting it
-
tried but not worked.
i noticed that i had this objects pointer saved in a QList some were else .
that caused the crash but i dont have any idea of fixing it -
@mahd96 said in Detected QWeakPointer creation in a QObject being deleted:
i dont have any idea of fixing it
First remove the pointer from the list then delete, this way you make sure nobody uses the pointer after the object was deleted.
-
To add to @jsulm and since these pointer are moving around, you should always check their validity before using them.
-
@SGaist to validate them i try to Use QPointer but i had some QSet in my code like this :
QSet<TempClass*>
i changed it to QSet<Pointer<TempClass>>
it seems to be alright but i get some compile error in qhash.h!
:"none of 45 overloads could convert all the argument types.do you have any idea how to solve it?
or another way of validation. -
Can you explain a bit more the goal of these sets and lists of QPointer ?
-
@SGaist
in first class i create some of this TempClasses but some actions most be done on them in second class so it have alist of class one items in a QSet.
for some reasons Class one removes some of its objects. but class two have their pointer in its list so when it try to access them app crashes.
i used QPointer to save TempClasses in QSet so i can validate them before using them but i got a compile error! -
Then shouldn't you rather share these data more cleanly ? Maybe consider using a model or a list a class that allows proper management rather than having unsynchronised list/set/whatever_containers.