1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| void tcpDlg::receiveData()
{
//We call QTcpServer::newPendingConnection(),
//which returns the QTcpSocket representing the server side of the connection.
//By connecting QTcpSocket::disconnected() to QObject::deleteLater(),
//we ensure that the socket will be deleted after disconnecting.
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater()));
//The encoded data is read
QByteArray data = clientConnection->read(1000);
MesBox->append(data);
//we will close the connection after QTcpSocket has finished writing the data to the network
clientConnection->disconnectFromHost();
} |