Results 1 to 3 of 3

Thread: How to safely delete an Object?

  1. #1
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to safely delete an Object?

    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

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to safely delete an Object?

    Sounds good to me.

  3. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to safely delete an Object?

    Here is something u'll find very useful :

    http://silmor.de/33

Similar Threads

  1. Replies: 4
    Last Post: 19th February 2009, 11:10
  2. Help with Q_PROPERTY with object pointer
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 17:31
  3. Is it bad to delete an object during its event handler?
    By codeslicer in forum Qt Programming
    Replies: 3
    Last Post: 30th December 2008, 16:14
  4. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38
  5. Passing Object to dll
    By ankurjain in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 09:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.