View Full Version : Closing QMainWindow
kalwi
9th April 2013, 18:40
I would close QMainWindow, when QDialog don't return QDialog::Accepted. I tried this->close(); and qApp->quit(); but it doesn't work. I would like run destructor while closing main window to delete pointers. Any ideas? I tried implement void closeEvent(QCloseEvent* event), but I don't know how do it correctly (remember about destructor).
K4ELO
9th April 2013, 21:08
Have the dialog emit a signal when the "cancel" button is clicked. Set up a connection from the signal to the slot in the mainwindow where you called the dialog to a slot in the mainwindow where you can call quit();
ChrisW67
9th April 2013, 21:54
I tried this->close();
We have know idea what object this is.
and qApp->quit(); but it doesn't work.
Sure it does. You need to produce evidence of your claim.
I would like run destructor while closing main window to delete pointers.
This is unrelated. The destructor is run when the object is destroyed (by scope or explicit delete; except in cases of termination for unhandled exceptions). A typical QMainWindow instance is stack allocated and destroyed when it goes out of scope after the main program event loop exits. The event loop exits when qApp->quit() is called or (typically) when the last top-level window is hidden (closed).
I tried implement void closeEvent(QCloseEvent* event), but I don't know how do it correctly (remember about destructor).
closeEvent() has nothing to do with the destructor of the object. The QWidget::closeEvent() docs show exactly how to use it. The Application Example shows it in a complete application.
Reduce your program to a small, single file, complete program that demonstrates the problem and post it here.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.