Exit gracefully on Ctrl-C and service stop
This commit is contained in:
parent
7bd7a94bd5
commit
542a5b7636
1 changed files with 6 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "battery.h"
|
||||
#include "settings.h"
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -44,6 +45,11 @@ int main(int argc, char** argv)
|
|||
QObject::connect(updater, SIGNAL(timeout()), battery, SLOT(updateData()));
|
||||
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();
|
||||
|
||||
return retval;
|
||||
|
|
Loading…
Reference in a new issue