poc prevent duplicate instances
This commit is contained in:
parent
3a16b333b2
commit
cb17bcb435
2 changed files with 25 additions and 2 deletions
|
|
@ -5,7 +5,7 @@ QMAKE_LFLAGS += --target=x86_64-w64-mingw32 -g -Wl,-pdb= -v
|
||||||
DEFINES += DEBUG
|
DEFINES += DEBUG
|
||||||
CONFIG += debug console
|
CONFIG += debug console
|
||||||
|
|
||||||
QT += widgets
|
QT += widgets network
|
||||||
INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont"
|
INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont"
|
||||||
DESTPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont"
|
DESTPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont"
|
||||||
VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont"
|
VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont"
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,11 @@
|
||||||
|
|
||||||
//#define QTBLESSED
|
//#define QTBLESSED
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
#include <QLocalSocket>
|
||||||
|
#include <QLocalServer>
|
||||||
|
#include <QString>
|
||||||
//#include "contclasses.h"
|
//#include "contclasses.h"
|
||||||
#include "qtclasses.h"
|
#include "qtclasses.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
@ -18,9 +21,29 @@ QApplication* createApplication(int &argc, char *argv[])
|
||||||
return new QApplication(argc, argv);
|
return new QApplication(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isSingleInstanceRunning(QString appName) {
|
||||||
|
QLocalSocket socket;
|
||||||
|
socket.connectToServer(appName);
|
||||||
|
bool isOpen = socket.isOpen();
|
||||||
|
socket.close();
|
||||||
|
return isOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
QLocalServer* startSingleInstanceServer(QString appName) {
|
||||||
|
QLocalServer* server = new QLocalServer;
|
||||||
|
server->setSocketOptions(QLocalServer::WorldAccessOption);
|
||||||
|
server->listen(appName);
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
int main (int argc, char* argv[]) {
|
int main (int argc, char* argv[]) {
|
||||||
//QApplication::setStyle("windowsvista");
|
//QApplication::setStyle("windowsvista");
|
||||||
|
//Check if running
|
||||||
|
//https://stackoverflow.com/questions/48060989/qt-show-application-if-currently-running
|
||||||
|
if (!isSingleInstanceRunning("Mixer"))
|
||||||
|
startSingleInstanceServer("Mixer");
|
||||||
|
else exit(0);
|
||||||
|
|
||||||
//INIT CONT
|
//INIT CONT
|
||||||
log_debugcpp("main init");
|
log_debugcpp("main init");
|
||||||
osh->reloadEndpointHandlers();
|
osh->reloadEndpointHandlers();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue