QCtrlSignals  1.0.0
A library to catch and handle windows and unix signals, in a cross platform manner
qctrlsignalhandler.h
1 #ifndef QCTRLSIGNALHANDLER_H
2 #define QCTRLSIGNALHANDLER_H
3 
4 #include <QObject>
5 #include <QScopedPointer>
6 #include <QLoggingCategory>
7 
8 #include <functional>
9 
10 #ifdef Q_OS_WIN
11 #include <qt_windows.h>
12 #else
13 #include <signal.h>
14 #endif
15 
16 class QCtrlSignalHandlerPrivate;
19 {
20  Q_OBJECT
21  friend class QCtrlSignalHandlerPrivate;
22  friend class QCtrlSignalHandlerInstance;
23 
26 
27 public:
30 #ifdef Q_OS_WIN
31  SigInt = CTRL_C_EVENT,
32  SigTerm = CTRL_BREAK_EVENT
33 #else
34  SigInt = SIGINT,
35  SigTerm = SIGTERM
36 #endif
37  };
38 
40  static QCtrlSignalHandler *instance();
41 
43  bool registerForSignal(int signal);
45  bool unregisterFromSignal(int signal);
46 
48  bool isAutoQuitActive() const;
49 
50 public slots:
53 
54 signals:
56  void sigInt();
58  void sigTerm();
59 
61  void ctrlSignal(int signal);
62 
65 
66 private:
68 
69  explicit QCtrlSignalHandler();
71 };
72 
73 Q_DECLARE_LOGGING_CATEGORY(logQCtrlSignals)
74 
75 #endif // QCTRLSIGNALHANDLER_H
CommonSignals
Common signals, that are available on all platforms.
static QCtrlSignalHandler * instance()
Returns the singleton instance of the signal handler.
void autoQuitActiveChanged(bool autoQuitActive)
NOTIFY-Accessor for QCtrlSignalHandler::autoQuitActive.
bool unregisterFromSignal(int signal)
Unregisters this handler from the given signal.
void sigTerm()
Shortcut signal for QCtrlSignalHandler::SigTerm.
bool isAutoQuitActive() const
READ-Accessor for QCtrlSignalHandler::autoQuitActive.
void ctrlSignal(int signal)
Will be emitted if a registered signal occures.
bool registerForSignal(int signal)
Registers this handler for the given signal.
Mapped to CTRL_BREAK_EVENT on windows and SIGTERM on unix.
void sigInt()
Shortcut signal for QCtrlSignalHandler::SigInt.
Mapped to CTRL_C_EVENT on windows and SIGINT on unix.
void setAutoQuitActive(bool autoQuitActive)
WRITE-Accessor for QCtrlSignalHandler::autoQuitActive.
bool autoQuitActive
Specifies, whether the handler should automatically handle signals that "quit" the app...
A class to listen for "CTRL-Signals".