Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why no memory gets freed after closeEvent?

Why no memory gets freed after closeEvent?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 758 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tapsa
    wrote on last edited by
    #1

    I have an application that needs to launch separate main windows, because I need to copy data between them. I could use shared memory between separate processes, but it is much easier to be able to dynamically open and close multiple main windows.

    void AGEMainWindow::closeEvent(QCloseEvent *event)
    {
        --AGEMainWindow::openEditors;
        if(true)
        {
            event->accept();
        }
        else
        {
            event->ignore();
        }
    }
    

    The auto-generated destructor deletes user interface. Either it is not called or it doesn't free any memory.

    How do I completely delete and free all user interface memory when closing one main window?

    In wxWidgets this was achieved using only:

    Destroy();
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      how do you create instances of AGEMainWindow??
      You can use the Window Attribute Qt::WA_DeleteOnClose.
      For instance in the constructor you can do

      AGEMainWindow::AGEMainWindow(const QWidget* _parent)
          : QMainWindow(_parent)
      {
          setAttribute(Qt::WA_DeleteOnClose, true);
          ...
      }
      

      So after the closeEvent is accepted the Window object will be destroyed

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alex_malyu
        wrote on last edited by
        #3

        By default close does not delete anything.
        It just hides the window.

        Widget can have attribute WA_DeleteOnClose set as mentioned above,
        But if you want to handle deletion yourself you normally just call
        delete yourself.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved