Nyaruko
Nyaruko

Reputation: 4459

How to tell the client has end the connection during IPC using QLocalSocket?

I have two programs doing IPC using QLocalSocket & QLocalServer, I have managed to implement the connection and send the data successfully.

However, for the QLocalServer side, how can I know a connection is ended by client (like the client program quit.)?

So that I could release the resource of corresponding socket on server side?

Upvotes: 1

Views: 518

Answers (1)

code_fodder
code_fodder

Reputation: 16321

You can connect the void QLocalSocket::disconnected() signal from QLocalHost to a slot in your class:

connect(mySocket, &QLocalSocket::disconnected, this, &MyClass::socketDisconnected, Qt::QueuedConnection);

Or you can connect to the stateChange (for more detailed version), something like:

// Connect like this
connect(mySocket, &QLocalSocket::stateChanged, this, &MyClass::socketNewState, Qt::QueuedConnection);

// Implement a slot that handles the various states...
MyClass::socketNewState(QLocalSocket::LocalSocketState socketState)
{
   qDebug() << "New state is " << socketState << endl;
}

Upvotes: 1

Related Questions