일부 서버 응용 프로그램에서 작업 중입니다.이 스켈레톤은 서브 클래스 QTcpServer
이고 이름이 UeTcpServer
입니다. 서버 응용 프로그램은 정상적으로 시작 내가 ueSlotTcpServerNewConnection()
에 중단 점을 배치 할 때,새 연결시 QTcpServer :: hadPendingConnections()가 false를 반환합니다.
connect(this->ueTcpServer(),
SIGNAL(newConnection()),
this,
SLOT(ueSlotTcpServerNewConnection()));
를 통해 UeTcpServer
의 newConnectionSignal
에 연결 한 후 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
을 반환합니다. 왜? 또한 docs에 명시된대로
내 자신의'QTcpServer' 사용법을 보면서'while (QTcpSocket * conn = server-> nextPendingConnection()) {'을 사용하는 데 문제가 없었습니다. 그래서 내 질문은 ...'hasPendingConnections'가 false를 반환하면'nextPendingConnection'은 NULL/nullptr을 리턴합니까? 아니면 실제로 유효한 연결을 리턴합니까? –
@ G.M. 'if (this-> ueTcpServer() -> hasPendingConnections())'를 제거/주석하면'QTcpSocket'에'NULL' 포인터가 생깁니다. – KernelPanic
응용 프로그램의 QTcpServer 하위 클래스에서 incomingConnection을 다시 구현 했습니까? 그렇다면 addPendingConnection을 호출하는 것을 잊어 버릴 수도 있습니다. –