Merge pull request #129 from jonaski/signalslots

Fix signal-slot issues
This commit is contained in:
Itay Grudev 2021-03-26 09:59:27 +02:00 committed by GitHub
commit 9f65e9c7fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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()