0

我正在开发一些服务器应用程序,该框架是子类化QTcpServer的,命名为UeTcpServer. ueSlotTcpServerNewConnection()服务器应用程序正常启动,当我在连接到UeTcpServer的断点时newConnectionSignal通过

connect(this->ueTcpServer(),
        SIGNAL(newConnection()),
        this,
        SLOT(ueSlotTcpServerNewConnection()));

然后使用连接到服务器应用程序Linux terminal,断点在ueSlotTcpServerNewConnection()插槽内激活:

void UeMainWindow::ueSlotTcpServerNewConnection()
{
    if(this->ueTcpServer()->hasPendingConnections())
    {
        QTcpSocket* incomingSocket=this->ueTcpServer()->nextPendingConnection();

        this->ueSlotAddEventInfoLog(0,
                                    tr("New incoming connection from host")
                                    .append(" ")
                                    //.append(this->ueTcpServer()->nextPendingConnection()->peerAddress().toString())
                                    .append(incomingSocket->peerName())
                                    .append(" ")
                                    .append(tr("with IP address"))
                                    .append(" ")
                                    .append(incomingSocket->peerAddress().toString())
                                    .append(" ")
                                    .append(tr("using port"))
                                    .append(" ")
                                    //.append(this->ueTcpServer()->nextPendingConnection()->peerPort()));
                                    .append(QString::number(incomingSocket->peerPort())));
    }   // if
}   // ueSlotTcpServerNewConnection

但是,this->ueTcpServer()->hasPendingConnection()返回false. 为什么?

4

1 回答 1

0

我忘记打电话addPendingConnection(QTcpSocket *socket了,incomingConnection(qintptr socketDescriptor)正如文档中所述:

void UeTcpServer::incomingConnection(qintptr socketDescriptor)
{  
    QTcpSocket* newSocket=new QTcpSocket(this);

    newSocket->setSocketDescriptor(socketDescriptor);

    this->addPendingConnection(newSocket);
}   // incomingConnection

现在可以了。

于 2016-07-08T09:58:27.007 回答