0

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

QTcpSocket * sock = tcpServer->nextPendingConnection();

?

4

1 回答 1

0

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();
}
于 2013-04-08T09:45:52.977 回答