Results 1 to 3 of 3

Thread: Deleting a QWidget derived object manually

  1. #1
    Join Date
    Dec 2009
    Posts
    62
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Deleting a QWidget derived object manually

    Hi

    I just wanted to check if this is ok.

    I have a StackedView that can contain zero or more of my custom Widgets. As it is now all my Widgets has the StackedView as parent so when it is deleted, so are the widgets. However the Widgets are created and disposed dynamically during the execution of my program. In some scenarios I really want to delete the Widget in the StackedView immidiatly and not wait for the StackedView to be deleted.

    So my question is simply. If I have a Widget that has a parent QWidget, is it good practice to sometimes delete the widget manually and still keep the parent deletion as a backup option?

  2. #2
    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: Deleting a QWidget derived object manually

    Its fine enough to delete yourself. The children which has been deleted wont be deleted again when the parent is deleted.
    Qt eases you not to bother about child deletions but doesnt restrict you from manually doing it.

  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Deleting a QWidget derived object manually

    Your question was if it is good practice. My answer is: As long as you as the developer can easily keep up where and why something happens, everything is fine. Qt obviously is designed for that practice, because of the existence of QEvent::ChildRemoved and QChildEvent.

    Johannes

Similar Threads

  1. Can't add an object derived from QWidget in a layout.
    By Netich in forum Qt Programming
    Replies: 1
    Last Post: 14th January 2010, 22:55
  2. Replies: 2
    Last Post: 20th September 2009, 03:52
  3. QWidget-derived Application Plugins
    By SnarlCat in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2008, 19:25
  4. How to call QValidator derived object
    By bruccutler in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2007, 18:07
  5. Replies: 1
    Last Post: 2nd May 2006, 22:11

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.