Results 1 to 2 of 2

Thread: Deleting QApplication and QMainWindow Objects ?

  1. #1
    Join Date
    Apr 2016
    Posts
    2
    Qt products
    Qt3
    Platforms
    Android

    Default Deleting QApplication and QMainWindow Objects ?

    I understand that the QWidget will delete its child widgets appropriately. What about the objects of QMainwindow, the super parent and QApplication. Do I need to delete them explicitly to clear the memory? If it is an executable, (i.e. the QMainWindow and QApplication objects are created in main function), it may be fine because the entire application is going to exit anyway. But what happens in case of a dll (i.e. QMainWindow and QApplication objects are created inside an exported dll-function)?
    In this case, The dll-function is invoked from a parent application and later, QMainWindow is closed by the user. Remember that the parent application is still running. When the same session of parent application invokes the dll-function again, the Qt objects are created newly.
    So is there any chance of memory issues when it happens multiple time?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Deleting QApplication and QMainWindow Objects ?

    In the case of a normal application, you will most likely create QApplication and your main window instance on the stack of main(), so they get deleted when main() ends.

    In case of it being hidden inside a DLL, you could set the Qt::WA_DeleteOnClose attribute on the window so it gets deleted when it gets closed.
    You could also connect the application object's lastWindowClosed() signal to its own deleteLater() slot, or you keep just this object around for further use.

    Cheers,
    _

Similar Threads

  1. Deleting QMainWindow and QApplication Objects
    By mqt in forum Qt Programming
    Replies: 13
    Last Post: 16th May 2015, 10:02
  2. Deleting objects in their event handler
    By drhex in forum Qt Programming
    Replies: 7
    Last Post: 6th May 2009, 16:08
  3. creating/deleting Objects // memory leaks
    By janus in forum Qt Programming
    Replies: 4
    Last Post: 27th March 2008, 18:17
  4. Q_FOREACH deleting objects
    By veda in forum Qt Programming
    Replies: 31
    Last Post: 22nd May 2007, 13:05
  5. Reponsabilities of QApplication and QMainWindow classes
    By yellowmat in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2006, 16:21

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.