QTcpServer::hadPendingConnections() returns 新连接时为 false

QTcpServer::hadPendingConnections() returns false upon new connection

我正在开发一些服务器应用程序,其骨架是 QTcpServer 的子类,名为 UeTcpServer。服务器应用程序正常启动,当我在 ueSlotTcpServerNewConnection() 中放置断点时,它通过

连接到 UeTcpServernewConnectionSignal
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()returnsfalse。为什么?

我忘记从 incomingConnection(qintptr socketDescriptor) 调用 addPendingConnection(QTcpSocket *socket,正如 docs:

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

    newSocket->setSocketDescriptor(socketDescriptor);

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

现在可以使用了。