Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
catch app close on Android and iOS
I need to save some data before application closes, on Android I have signal when backbutton is pressed and I can save data. On iOS there is no back button, OS will close my app at some point, can I be sure in code to catch this and save data before closing ?
QCoreApplication::aboutToQuit()signal or after
app.exec()(might be already too late though) in your main().
This might only work when the running app is closed by the user and not when the system forcefully decides to shutdown your application.
@raven-worx Thanks. So, will this work on iOS ? I mean OS will close application in ordinary manner or forcefully?
i am not quite sure, since i am not very experienced with iOS. Give it a try by switching the app to background and close it afterwards from the "task manager".
On Android the system might stop your application (when in background) in order to claim back resources.
@raven-worx In short it would be best to save data when app is going in background (this will catch iOS and Android case ) and when backbutton on Android is used, right?
In short it would be best to save data when app is going in background (this will catch iOS and Android case )
probably yes, you can try to check the application state (QML)
This is actually the better approach than my first advice!
@raven-worx Thanks, I will do some testing but this seems to solve my problem.
application.state == Qt.ApplicationSuspended // and the following, depending if the state also changes to 'suspended' on quit or not application.aboutToQuit.connect(saveFunction)