Why no memory gets freed after closeEvent?



  • 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();
    


  • 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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.