1
0
mirror of https://github.com/itay-grudev/SingleApplication.git synced 2025-04-01 01:52:39 +08:00

Fix signal-slot issues

This commit is contained in:
Jonas Kvinge 2021-03-26 00:16:25 +01:00
parent 4aeac8fa3e
commit 4052d37110

View File

@ -321,22 +321,22 @@ void SingleApplicationPrivate::slotConnectionEstablished()
QLocalSocket *nextConnSocket = server->nextPendingConnection(); QLocalSocket *nextConnSocket = server->nextPendingConnection();
connectionMap.insert(nextConnSocket, ConnectionInfo()); connectionMap.insert(nextConnSocket, ConnectionInfo());
QObject::connect(nextConnSocket, &QLocalSocket::aboutToClose, QObject::connect(nextConnSocket, &QLocalSocket::aboutToClose, this,
[nextConnSocket, this](){ [nextConnSocket, this](){
auto &info = connectionMap[nextConnSocket]; auto &info = connectionMap[nextConnSocket];
Q_EMIT this->slotClientConnectionClosed( nextConnSocket, info.instanceId ); this->slotClientConnectionClosed( nextConnSocket, info.instanceId );
} }
); );
QObject::connect(nextConnSocket, &QLocalSocket::disconnected, nextConnSocket, &QLocalSocket::deleteLater); QObject::connect(nextConnSocket, &QLocalSocket::disconnected, nextConnSocket, &QLocalSocket::deleteLater);
QObject::connect(nextConnSocket, &QLocalSocket::destroyed, QObject::connect(nextConnSocket, &QLocalSocket::destroyed, this,
[nextConnSocket, this](){ [nextConnSocket, this](){
connectionMap.remove(nextConnSocket); connectionMap.remove(nextConnSocket);
} }
); );
QObject::connect(nextConnSocket, &QLocalSocket::readyRead, QObject::connect(nextConnSocket, &QLocalSocket::readyRead, this,
[nextConnSocket, this](){ [nextConnSocket, this](){
auto &info = connectionMap[nextConnSocket]; auto &info = connectionMap[nextConnSocket];
switch(info.stage){ switch(info.stage){
@ -347,7 +347,7 @@ void SingleApplicationPrivate::slotConnectionEstablished()
readInitMessageBody(nextConnSocket); readInitMessageBody(nextConnSocket);
break; break;
case StageConnected: case StageConnected:
Q_EMIT this->slotDataAvailable( nextConnSocket, info.instanceId ); this->slotDataAvailable( nextConnSocket, info.instanceId );
break; break;
default: default:
break; break;
@ -449,7 +449,7 @@ void SingleApplicationPrivate::readInitMessageBody( QLocalSocket *sock )
} }
if (sock->bytesAvailable() > 0){ if (sock->bytesAvailable() > 0){
Q_EMIT this->slotDataAvailable( sock, instanceId ); this->slotDataAvailable( sock, instanceId );
} }
} }
@ -462,7 +462,7 @@ void SingleApplicationPrivate::slotDataAvailable( QLocalSocket *dataSocket, quin
void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId ) void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId )
{ {
if( closedSocket->bytesAvailable() > 0 ) if( closedSocket->bytesAvailable() > 0 )
Q_EMIT slotDataAvailable( closedSocket, instanceId ); slotDataAvailable( closedSocket, instanceId );
} }
void SingleApplicationPrivate::randomSleep() void SingleApplicationPrivate::randomSleep()