Results 1 to 2 of 2

Thread: What is the right way of deleting widgets ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default What is the right way of deleting widgets ?

    I have a custom widget. Inside it I create some other widgets, without tellingt them the parent.
    When the main widget is closed, whats happen with them ? Are they auto-deleted or destroyed ? If they are not destroyed, have I memory leaks?
    Thanks.

  2. #2
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What is the right way of deleting widgets ?

    are these widgets arranged within a layout? in that case, they get reparented automatically which means they get destroyed when the layout gets destroyed. If you do't have a layout, they will not be destroyed - c++ does not have any garbage collector like java. And yes, then you have memory leaks (assuming you create the widgets with "new" and don't use smart pointers to store them).

    hth,
    Felix

  3. The following user says thank you to FelixB for this useful post:

    tonnot (13th February 2012)

Similar Threads

  1. QMdiSubWindows - Deleting
    By Kerubu in forum Newbie
    Replies: 1
    Last Post: 25th August 2009, 05:23
  2. Deleting controls
    By alisami in forum Newbie
    Replies: 1
    Last Post: 18th June 2008, 15:19
  3. Deleting QProcess
    By user_mail07 in forum Qt Programming
    Replies: 7
    Last Post: 29th January 2008, 18:55
  4. Deleting a row in QTable having custom widgets
    By madhu in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 10:55
  5. Deleting widgets in the destructors
    By vfernandez in forum Newbie
    Replies: 1
    Last Post: 2nd August 2006, 15:26

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.