将用户数据写入QTcpSocket

时间:2013-04-06 10:42:00

标签: qt

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

中读取
QTcpSocket * sock = tcpServer->nextPendingConnection();

1 个答案:

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