PDA

View Full Version : How to safely delete an Object?



dbrmik
6th March 2009, 16:49
Hi

One of my classes (MyClass) inherits from QObject (for signals/slot). This class is created by the GUI front end when I load a valid data file into my program. In the GUI constructor I set the pointer to MyClass to NULL.

If there is an existing instance of MyClass then it is deleted and its pointer set to NULL. (there will only ever be one instance of MyClass)

If a valid file is loaded, I check that the pointer is not NULL before deleting MyClass object (if there was one). Is this the correct way of doing this?

Is there a better way?

Regards

JimDaniel
6th March 2009, 17:15
Sounds good to me.

talk2amulya
6th March 2009, 17:23
Here is something u'll find very useful :

http://silmor.de/33