Pergunta

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?

main:

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

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

Can anyone tell me why the incomingConnection is not firing?

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

Foi útil?

Solução

Can anyone tell me why the incomingConnection is not firing?

Michelle, it seems you have made a typo. The signature of the aforementioned virtual protected method can be read in here. There is a slight difference between the argument of that and your variant.

The fix would be to modify the declaration and definition in your corresponding header and sources as follows:

void incomingConnection(quintptr socketDescriptor);
//                       ^

I would suggest to start using the Q_DECL_OVERRIDE macro as follows:

void incomingConnection(q**u**intptr socketDescriptor) Q_DECL_OVERRIDE;

This will make sure that you can get a compiler error when your Qt application is built with C++11 support, and when it is not, it will compile fine, too, but without giving an error. It is using the "override" context specifier introduced in C++11.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top