comparison src/runguard.h @ 228:37d5f4329449

Implement single running instance check to prevent problems with the SQLite database.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 20 Mar 2018 13:45:21 +0200
parents
children
comparison
equal deleted inserted replaced
227:07e7f254ef16 228:37d5f4329449
1 //
2 // Taken and modified from https://stackoverflow.com/questions/5006547/qt-best-practice-for-a-single-instance-app-protection
3 //
4 #ifndef RUNGUARD_H
5 #define RUNGUARD_H
6
7 #include <QObject>
8 #include <QSharedMemory>
9 #include <QSystemSemaphore>
10
11
12 class RunGuard
13 {
14
15 public:
16 RunGuard(const QString &key);
17 ~RunGuard();
18
19 bool isAnotherRunning();
20 bool tryToRun();
21 void release();
22
23 private:
24 const QString key;
25 const QString memLockKey;
26 const QString sharedmemKey;
27
28 QSharedMemory sharedMem;
29 QSystemSemaphore memLock;
30
31 Q_DISABLE_COPY(RunGuard)
32 };
33
34
35 #endif // RUNGUARD_H