2022-02-22 08:02:34 +00:00
|
|
|
#pragma once
|
2022-01-06 19:29:19 +00:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
class QLocalServer;
|
|
|
|
|
|
|
|
class SingleInstance : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
// uniqueName - the name of named pipe
|
|
|
|
// eventStr - optional event to send if another instance is detected
|
2022-02-21 18:03:38 +00:00
|
|
|
explicit SingleInstance(const QString& uniqueName, const QString& eventStr, QObject* parent = nullptr);
|
2022-01-06 19:29:19 +00:00
|
|
|
~SingleInstance() override;
|
|
|
|
|
|
|
|
bool isFirstInstance() const;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void secondInstanceDetected();
|
2022-02-21 18:03:38 +00:00
|
|
|
void eventReceived(const QString& eventStr);
|
2022-01-06 19:29:19 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void handleNewConnection();
|
|
|
|
|
|
|
|
private:
|
2022-02-21 18:03:38 +00:00
|
|
|
QLocalServer* m_localServer;
|
2022-01-06 19:29:19 +00:00
|
|
|
};
|