diff options
Diffstat (limited to 'src/singleapplication.cpp')
-rw-r--r-- | src/singleapplication.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/singleapplication.cpp b/src/singleapplication.cpp index 01b2e65..331268b 100644 --- a/src/singleapplication.cpp +++ b/src/singleapplication.cpp @@ -38,10 +38,22 @@ SingleApplication::~SingleApplication() void SingleApplication::bindLocalSocket() { m_localServer = new QLocalServer(this); - connect(m_localServer, SIGNAL(newConnection()), this, SLOT(slot_receiveMessage())); + connect(m_localServer, &QLocalServer::newConnection, this, &SingleApplication::slot_receiveMessage); - if(!m_localServer->listen(LOCALSERVER_KEY)) { - qWarning("Cannot bind local server [%s]", qUtf8Printable(LOCALSERVER_KEY)); + // check for running local server by connecting to it + QLocalSocket socket; + socket.connectToServer(LOCALSERVER_KEY); + if(socket.waitForConnected(LOCALSERVER_TIMEOUT)) { + // there is another server + qWarning("Another server is running"); + socket.close(); + return; + } else { + // no other server + QLocalServer::removeServer(LOCALSERVER_KEY); + if(!m_localServer->listen(LOCALSERVER_KEY)) { + qWarning("Cannot bind local server [%s]", qUtf8Printable(LOCALSERVER_KEY)); + } } } @@ -80,6 +92,11 @@ void SingleApplication::slot_receiveMessage() QByteArray argumentData = socket->readAll(); + // skip if we got no data + if(argumentData.isEmpty()) { + return; + } + QHash<QString, QVariant> params; QDataStream ds(argumentData); ds >> params; |