Yes, destructor is not the same as close event. If you want the message on close event, then put the message in the close event handler!
Yes, destructor is not the same as close event. If you want the message on close event, then put the message in the close event handler!
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
I apologize for writing it in a bit confusing way.
When I put the message in overloaded close event handler ("void MainWindow::closeEvent(QCloseEvent *event)") it gets displayed immediately after closing the window. The problem is, when I put the message in destructor instead, it gets displayed first when the whole app quits.
So my question is: why is the destructor not called immediately after I close the window? And how to make it being called after the window is closed?
Last edited by ecir.hana; 1st April 2013 at 01:33.
When you click the [x] button (or equivalent) you are triggering a close event and (maybe) hiding the window. You are not destroying the QMainWindow object hence the destructor is not called. The QMainWindow object is not destroyed until C++ scope rules dictate (stack allocated objects) or operator delete is called (heap allocated objects).
If you use the Qt::WA_DeleteOnClose attribute a heap-allocated QWidget object will be destroyed if the object's closeEvent() accepts the closure. It uses the QObject::deleteLater() call, so the deletion is deferred until the program returns to the Qt event loop. This attribute makes no sense if the QWidget object is stack-based (often the case for the program's main window).
Bookmarks