this may seem like a very simple question, but I want to dump some data whenever the QMainWindow
closes, so I used the following piece of code:
QObject::connect(MainWindow.centralwidget, SIGNAL(destroyed()), this, SLOT(close()));
But this doesn't seem to make it call close()
. Am I doing this wrong?.
Isn't the centralwidget suppose to be destroyed?.
Or perhaps the application closes before close()
can be called?.
Any other ways of doing it then?
You better to re implement one virtual function in your main MainWindow
class like this:
class MainWindow : public QMainWindow {
Q_OBJECT;
public:
MainWindow();
protected:
void closeEvent(QCloseEvent *event);
}
and then declare in source file:
void MainWindow::closeEvent(QCloseEvent *event) {
// do some data saves or something else
}
Good luck.
I'd try QGuiApplication::lastWindowClosed() instead.
Could you implement the closeEvent
function for your QMainWindow
and put your code there?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With