Exit gracefully on Ctrl-C and service stop

This commit is contained in:
Matti Viljanen 2020-04-26 11:32:03 +03:00
parent 7bd7a94bd5
commit 542a5b7636
No known key found for this signature in database
GPG key ID: CF32A1495158F888

View file

@ -4,6 +4,7 @@
#include "battery.h" #include "battery.h"
#include "settings.h" #include "settings.h"
#include <iostream> #include <iostream>
#include <signal.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -44,6 +45,11 @@ int main(int argc, char** argv)
QObject::connect(updater, SIGNAL(timeout()), battery, SLOT(updateData())); QObject::connect(updater, SIGNAL(timeout()), battery, SLOT(updateData()));
updater->start(3000); updater->start(3000);
// Exit gracefully on Ctrl-C and service stop
QObject::connect(&app, SIGNAL(aboutToQuit()), battery, SLOT(shutdown()));
signal(SIGINT, app.exit);
signal(SIGTERM, app.exit);
int retval = app.exec(); int retval = app.exec();
return retval; return retval;