From 65672d3dfbdf179df520bbaa5e7e7ba28a27db20 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Thu, 14 Dec 2017 21:55:00 +0200 Subject: Allow only one application instance fixes #141 --- include/RunGuard.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 include/RunGuard.h (limited to 'include') diff --git a/include/RunGuard.h b/include/RunGuard.h new file mode 100644 index 00000000..f9a9641a --- /dev/null +++ b/include/RunGuard.h @@ -0,0 +1,31 @@ +#pragma once + +// +// Taken from +// https://stackoverflow.com/questions/5006547/qt-best-practice-for-a-single-instance-app-protection +// + +#include +#include +#include + +class RunGuard +{ +public: + RunGuard(const QString &key); + ~RunGuard(); + + bool isAnotherRunning(); + bool tryToRun(); + void release(); + +private: + const QString key; + const QString memLockKey; + const QString sharedmemKey; + + QSharedMemory sharedMem; + QSystemSemaphore memLock; + + Q_DISABLE_COPY(RunGuard) +}; -- cgit 1.5.1