Results 1 to 3 of 3

Thread: Memory returned for child widgets after closing

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    26
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Memory returned for child widgets after closing

    QT handles memory deletion for child objects; I want to open a progress dialog and give a parent widget so I can set the Qt::Sheet window property.

    If I open a progress dialog; i.e. QProgressDialog *mydialog = new QProgressDialog("Busy...", "Stop", start, stop, parent), then can I assume that QT will recycle/free memory if I mydialog->close() and then open a new one later ?

    I'm concerned that if my function gets called many times I could do something nasty if QT doesn't take care of the memory. Is it the proper way, to just leave it for QT ?

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Memory returned for child widgets after closing

    As far as i know this should be fine, the attribute Qt::WA_DeleteOnClose is false by default, so you should be able to allocate memory (construct a widget) once and show-close... multiple times without the pointer to become invalid.

    //i didn't test this, i just deduced it should work, so you can make a small project and test with a debugger, or wait an answer for someone that can confirm with experience what i said (or maybe correct what i said - if i'm wrong).

  3. #3
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory returned for child widgets after closing

    Since you've got a QObject instance parented , as long as a parent exists,it's children will exist as well ( unless you delete them manually ).In your case, you can always check it with a QObjectList QObject::children() const method : as new dialogs appear,objectList.count() will get bigger as well.

    So you can delete newly created objects manually or use more a little more convinient QScopedPointer class.

Similar Threads

  1. Replies: 0
    Last Post: 17th November 2010, 17:07
  2. Child widgets
    By poporacer in forum Newbie
    Replies: 6
    Last Post: 12th August 2010, 03:04
  3. closing child dialog closes parent dialog
    By sparticus_37 in forum Newbie
    Replies: 2
    Last Post: 28th May 2010, 19:46
  4. Replies: 5
    Last Post: 18th April 2010, 23:31
  5. Closing all of the mainWindow's child dialogs
    By JPNaude in forum Qt Programming
    Replies: 4
    Last Post: 2nd October 2008, 13:18

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.