如何将用户数据写入 QTcpSocket 并读入
QTcpSocket * sock = tcpServer->nextPendingConnection();
?
Once you get your socket, you can just hook it up via signals/slots to get the data. You will need to save the socket via an instance variable.
Header:
QTcpSocket* sock;
Implementation File:
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();
}