Saving state when an app is closed

,

I want to save state when the user closes the app. Currently, I use vfunc_close_request. The problem is that this function is only called when the main window’s close button is clicked. State is not saved when I close the app from the commandline.

Is there an event emitted when the app is about to exit?

When an GTK application is closed, the signal Application::shutdown will be triggered.

So, you can connect to that signal for your save state routine.

Do note, that unlike Window::close_request, this is only called when the application quits. If you for example have two windows, closing one window will not trigger that signal.

1 Like

Don’t save state when the window gets closed: save state every time the state changes, as described in the corresponding tutorial.

If your application is dependant on coping with a non-standard way to terminate it, like sending a Unix signal via the terminal, then you’ll have to use something like a Unix signal watcher.

1 Like