c++ - Qt Parent to delete variable after child has closed -


i'm writing application in c++ using qt library. there central window (the parent) , children launched when needed. since number of these windows can open multiple times, display different data, i'm declaring objects new. here example of i've got:

home_window.hpp

view_window *somewindow; 

home_window.cpp

void home_window::on_windowbutton_clicked() {     somewindow = new view_window();     somewindow->show(); } 

what want do, delete object, when window closed reduce memory footprint of application. i've been able delete of objects contained in child window reduce memory usage, core object still lingers, , if, through single day user opens , closes 1000's of windows, , each object holds onto 40-50kb of memory, footprint of application goes couple of mbs of memory 100's of mbs of memory.

i've not been able find guide online allow me achieve this. considering slot , signal pair, know when window closed, sends qobject::destroyed() signal. issue, i've not tried setup signal , slot pair this.

any suggestions appreciated.

to delete window when closed, can set wa_deleteonclose attribute on it. on_windowbutton_clicked() should like:

void home_window::on_windowbutton_clicked() {     view_window* w= new view_window();     w->setattribute(wa_deleteonclose);     w->show(); } 

this way, don't have worry destroying w yourself, deleted automatically when closed.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -