Allow running only one instance of application.
parent
6f30949343
commit
5ebea2f7c9
@ -0,0 +1,31 @@
|
||||
#include "application.h"
|
||||
|
||||
Application::Application(int &argc, char **argv)
|
||||
:QApplication(argc, argv)
|
||||
{
|
||||
m_single = new QSharedMemory("ShredMemoryForOneInstanceOfProdejnaApp", this);
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
if (m_single->isAttached())
|
||||
{
|
||||
m_single->detach();
|
||||
}
|
||||
}
|
||||
|
||||
bool Application::lock()
|
||||
{
|
||||
if (m_single->attach(QSharedMemory::ReadOnly))
|
||||
{
|
||||
m_single->detach();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_single->create(1))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#ifndef APPLICATION_H
|
||||
#define APPLICATION_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QSharedMemory>
|
||||
|
||||
class Application : public QApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Application(int &argc, char **argv);
|
||||
~Application();
|
||||
|
||||
bool lock();
|
||||
|
||||
private:
|
||||
QSharedMemory *m_single;
|
||||
};
|
||||
|
||||
#endif // APPLICATION_H
|
Loading…
Reference in New Issue