Since this has not been answered, here is a really basic example.
In your ReceiveData slot, you will need to accept a connection to the server.
In Qt, QTcpServer does this by calling nextPendingConnection ().
That way, the newConnection QTcpServer slot will call your ReceiveData slot.
In your gotata slot, you can do something like:
void ReceiveData() { QTcpSocket *socket = server->nextPendingConnection(); if (!socket) return; qDebug("Client connected"); socket->waitForReadyRead(5000); QByteArray data = socket->readAll(); qDebug(data.constData()); socket->close(); }
Note. This is an example of a lock, waitForReadyRead will hang in the stream for up to 5000 milliseconds.
To make a non-blocking example, you need to connect another slot to the new connection ready signal.
source share