Unsolved QStackedWidget closeEvent
-
i have a qstackedwidget where i added a few widgets. in one of the widgets i wanna read settings from ini file. and in the widget's closeevent function i call the function to write the settings. however it isn't called (this is somewhat expected cause it's a child widget). however, if i get the widget from the class where i add the qstackedwidget, and call the widget's write settings function, closeevent is received.
any ideas?
-
Hi
You can try to call QWidget::close() that should also generate the closeEvent -
okay, and is it possible to write settings when qapplication::quit is about to be called?
-
@user4592357
Well you can hook up to
https://doc.qt.io/qt-5/qcoreapplication.html#aboutToQuit -
i was looking at it and it's private. can i still call it using signal-signal mechanism?
-
Well doc says
"Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user."
So try it :) -
Hi,
What about writing the settings in your widget destructor ?
-
i just tried writing in dtor, but my "main" class is a singleton and destructor isn't called (breakpoint not reached). is this because of singleton?
-
Then you should properly destroy your singleton before the application ends.
-
so, using aboutToQuit()?
-
No, delete it before returning the result of
app.exec()
.By the way, why do you need a singleton for ?
-
it's a game and i made it a singleton
-
I fail to see the motivation of introducing that pattern for a game. Can you give more details ?
-
there can be only one instance of a game that's why i used it
-
Are you handling several games in the application ?
-
no, just one
-
Then there's really no need for a singleton, just instantiate your game object once.