Results 1 to 5 of 5

Thread: To delete or not to delete....

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Smile To delete or not to delete....

    Hey,
    I have a pretty fundamental question that I cannot seem to find the answer for in either the documentation or the forums.

    Which items should I call delete xyx; on, and which items do I not? Is there a hard-fast rule? Since I read the other day that all items derived from QWidget, do not need to be deleted because Qt deletes them automatically.

    I say this because before I removed the deletes, I was getting lots of crashes. But now I worry that I am creating lots of memory leaks.

    Thanks,

    Phil Winder

  2. #2
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: To delete or not to delete....


  3. #3
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: To delete or not to delete....

    Thanks for that Janus,
    but what about new classes that I have derived from say QObject. Would I have to implement my own delete's in the destructor, or does the QObject take care of that?

    Cheers,
    Phil

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: To delete or not to delete....

    May be this will help u understand more

  5. #5
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: To delete or not to delete....

    Ahhh, thanks aamer4yu.
    So would I have to reimplement the children() function in my classes?
    E.g. for an XML parser class, called QgetXMLData, how would I implement a child deleter? Or could I just cheat and set all the new objects' parent to the parent of QgetXMLData?

    Cheers again,
    Phil

Similar Threads

  1. Delete dialog
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 12:42
  2. Deleting from TreeWidget... Memoryleak
    By VireX in forum Qt Programming
    Replies: 5
    Last Post: 1st June 2007, 21:33
  3. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38
  4. Delete all members in a QGraphicsItemGroup
    By vmferreira in forum Qt Programming
    Replies: 3
    Last Post: 17th August 2006, 18:47
  5. How to explicitely delete a QDir?
    By alan in forum Newbie
    Replies: 2
    Last Post: 13th February 2006, 17:48

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
  •  
Qt is a trademark of The Qt Company.