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 に答える