Question

I currenlty have a blocking model and the code where my client receives data is as follows

QByteArray tick_stream;
clntSocket->waitForReadyRead(-1);
tick_stream = clntSocket->read(800);

Now I believe clntSocket->waitForReadyRead(); should only unblock when there is data to be read from the socket however it seems that it unblocks by itself and tick_stream is empty any suggetsions on what might be going wrong ?

Was it helpful?

Solution

You should check for errors, because it can happen that the method will return immediately on error.

From QtDoc:

bool QIODevice::waitForReadyRead(int msecs) [virtual]

Blocks until new data is available for reading and the readyRead() signal has been emitted, or until msecs milliseconds have passed. If msecs is -1, this function will not time out.

Returns true if new data is available for reading; otherwise returns false (if the operation timed out or if an error occurred).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top