如何将用户数据写入QTcpSocket并在
中读取QTcpSocket * sock = tcpServer->nextPendingConnection();
答案 0 :(得分:0)
一旦你得到你的插座,你可以通过信号/插槽连接它来获取数据。您需要通过实例变量保存套接字。
部首:
QTcpSocket* sock;
实施档案:
YourClass::someMethod {
this->sock = tcpServer->nextPendingConnection();
connect(this->sock, SIGNAL(readyRead()), this, SLOT(startRead()));
}
void YourClass::startRead {
char buffer[1024] = {0};
this->sock->read(buffer, client->bytesAvailable());
cout >> buffer >> endl;
this->sock->close();
}