Results 1 to 4 of 4

Thread: how to kill parent widget?

  1. #1
    Join Date
    Jan 2006
    Posts
    80
    Thanks
    1
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default how to kill parent widget?

    My application calls another widget from the current and i never need the previous widget.
    So i want to kill the parent widget to avoid memory leak.

    I want to solve this problem as my widgets chains a lot.

    Can anybody help?

    Mahe2310

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: how to kill parent widget?

    Qt Code:
    1. delete pWidget;
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Jan 2006
    Posts
    80
    Thanks
    1
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: how to kill parent widget?

    Quote Originally Posted by zlatko
    Qt Code:
    1. delete pWidget;
    To copy to clipboard, switch view to plain text mode 

    If i am reusing it again. then ?

    pWidget name should be a global variable.. Right???
    that means all the widgets should be global...

    But if we are declaring these widget together in a header file and calls the header file by each of the file,
    then redeclaration error is generated.

    If i declare them static in the headers then once we delete it will not be created again.


    Mahe2310

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to kill parent widget?

    Try setting Qt::WA_DeleteOnClose attribute or invoking QObject::deleteLater(), but make sure that "parent" widget is not a parent of other windows, because it will delete them also. Another alternative is to turn your windows into singletons and just hide them when you don't need them.

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. let parent widget grow with child widget?
    By BeS in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2009, 11:17
  3. Replies: 6
    Last Post: 3rd September 2008, 14:27
  4. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:00
  5. Referencing Parent Widget from Child
    By taylor34 in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2006, 15:13

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.