Results 1 to 4 of 4

Thread: QWidget delete at once

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default QWidget delete at once

    I'm manipulating a lots of QWidget, but I also delete and replace them quite often.

    I know that QT keeps a pool of QWidget, just in case they are reloaded again. Is there a way to really delete a QWidget at once?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWidget delete at once

    There's no widget pool, just their parents that keep references to them.
    To delete a widget just call QWidget::deleteLater(), and it will be deleted the next time the event loop gains control.

    You can also call delete myWidget; but make sure to also make it null afterwards.

  3. #3
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QWidget delete at once

    So if I'm creating / deleting a large amount of QWidget and not getting back my memory there is an issue somewhere right ?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWidget delete at once

    Make sure every widget has a parent(that way you know that when deleting a widget all its children will be also deleted) and then check for leaks somewhere else in your program.
    You can use a profiler to get some idea about where exactly the leaks are occurring.

  5. The following user says thank you to marcel for this useful post:

    bunjee (14th February 2008)

Similar Threads

  1. Dynamic widget not displayed upon Qwidget
    By ashukla in forum Qt Programming
    Replies: 5
    Last Post: 17th December 2007, 11:11
  2. Delete dialog
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 12:42
  3. Replies: 3
    Last Post: 8th March 2007, 14:54
  4. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38
  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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.