PDA

View Full Version : QLocalServer incomingConnection method never calls, but newConnection signal sent



ocgltd
14th March 2014, 04:07
I am creating a simple QSocketServer in Qt. The socket starts to listen, but the incomingConnection method never seems to run. Can someone explain what is wrong here?

in main:

m_pipeserver = new PipeServer(this);
if (m_pipeserver->listen("test.sock")) {
qDebug() << "STARTED";
}


in pipeserver.h

class PipeServer : public QLocalServer
{
Q_OBJECT
public:
PipeServer(Controller *parent = 0);
protected:
void incomingConnection(qintptr socketDescriptor);
pipeserver.cpp

PipeServer::PipeServer(Controller *parent)
{
}
void PipeServer::incomingConnection(qintptr socketDescriptor)
{
qDebug() << "NEW CONNECTION";
// etc...


I see the STARTED message, but never see the NEW CONNECTION when I run:

socat -v READLINE unix-connect:/tmp/test.sock

Just for fun I hooked a slot method onto the newConnection signal and that method DOES fire when I connect. So why isn't the incomingConnection method firing?

ChrisW67
14th March 2014, 06:29
1. The parameter type for incomingConnection() is quintptr not qintptr, so your function is not overriding the existing virtual. Typically you process new connections in response to the newConnection() signal, not by overriding the incomingConnection() method.
2. "test.sock" and "/tmp/test.sock" may not be the same socket.