PDA

View Full Version : emit error for QLocalSocket



raj_iv
30th August 2011, 11:30
Hi,

I am implementing 'Local fortune server' example (from Qt 4.7.3) as a service on Windows.
What i want is that when someone paused the service, the local server should notify the error to the connected local socket (local fortune client). The error can be QLocalSocket::ServerNotFoundError.
Now, How to generate this error from server example. Please look at the following code where i want to generate this error.



void FortuneServer::incomingConnection(quintptr socketDescriptor)
{
if (disabled) {
// here i want to emit QLocalSocket::ServerNotFoundError
return;
}

QString fortune = fortunes.at(qrand() % fortunes.size());
FortuneThread *thread = new FortuneThread(socketDescriptor, fortune, this);
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}

void FortuneServer:: pause()
{
disabled = true;
}

high_flyer
31st August 2011, 09:05
I am not sure what is the problem you have.
From what I understand you don't have a problem with pausing your service, and to know that it is paused right?
If that is correct, then what is left is that you don't know how to send a message to your client?
If so, do it just like it was a fortune cookie.
Just make a new kind of message, lets say StatusMsg, and insert the logic in the client to react to that sort of messages, analogue to the fortune cookies.
If its neither, please explain more.

wysota
31st August 2011, 11:14
I think he doesn't want to send a message. He wants the connection from the client to be rejected. Personally I don't think this makes sense, in such situation one could just remove the local socket.