将用户数据写入QTcpSocket

将用户数据写入QTcpSocket,qt,Qt,如何将用户数据写入QTcpSocket并读入 QTcpSocket * sock = tcpServer->nextPendingConnection(); ?一旦您获得了套接字,您就可以通过信号/插槽将其连接起来以获取数据。您需要通过实例变量保存套接字 标题: QTcpSocket* sock; 实施文件: YourClass::someMethod { this->sock = tcpServer->nextPendingConnection();

如何将用户数据写入QTcpSocket并读入

QTcpSocket * sock = tcpServer->nextPendingConnection();

一旦您获得了套接字,您就可以通过信号/插槽将其连接起来以获取数据。您需要通过实例变量保存套接字

标题:

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();
}