gui/main: refactor signal handler
This commit is contained in:
parent
7b09b2fe60
commit
9434b9d590
@ -1,15 +1,19 @@
|
|||||||
#include "appwindow.h"
|
#include "appwindow.h"
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
|
#ifdef Q_OS_UNIX
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static QApplication *app;
|
static QApplication *app;
|
||||||
static AppWindow *window;
|
static AppWindow *window;
|
||||||
|
|
||||||
void sig_handler(int s) {
|
#ifdef Q_OS_UNIX
|
||||||
|
static void tryExitGracefully(int s) {
|
||||||
Q_UNUSED(s)
|
Q_UNUSED(s)
|
||||||
window->close();
|
window->close();
|
||||||
app->quit();
|
app->quit();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
app = new QApplication(argc, argv);
|
app = new QApplication(argc, argv);
|
||||||
@ -18,7 +22,10 @@ int main(int argc, char *argv[]) {
|
|||||||
window = new AppWindow;
|
window = new AppWindow;
|
||||||
QCoreApplication::setApplicationVersion(window->getAppVersion() + "-" +
|
QCoreApplication::setApplicationVersion(window->getAppVersion() + "-" +
|
||||||
window->getAppGitHash().left(9));
|
window->getAppGitHash().left(9));
|
||||||
signal(SIGINT, sig_handler);
|
|
||||||
|
#ifdef Q_OS_UNIX
|
||||||
|
signal(SIGINT, tryExitGracefully);
|
||||||
|
#endif
|
||||||
auto rc = app->exec();
|
auto rc = app->exec();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user