PDA

View Full Version : QTcpSocket waitForReadyRead() not re-emitting signal



alitoh
1st November 2012, 19:46
Hi. I have a QTcpScocket whose readyReady() signal is connected to a slot that handles it.

*Outside* of the scope of said slot I have another method that writes to the socket and then I call waitForReadyRead() in this manner


m_tcpSocket->write((char *)buffer, bufferSize);
m_tcpSocket->waitForReadyRead(5000);

because I need that particular code block to be blocking until I get a response.

Problem is that if I use the waitForReadyRead method, it never re-emits the signal so that the slot can handle the incoming data. If I remove the waitForReadyRead, it works just fine, but it is non-blocking, so the tcpSocket just writes a second message without waiting for the reply to the first one.

Reading the documentation (http://doc.qt.digia.com/qt/qiodevice.html#waitForReadyRead), it says that
If called from within a slot connected to the readyRead() signal, readyRead() will not be reemitted., which is not my case. I am NOT calling waitForReadyRead from within a slot. And I understand from that sentence that, if not called from within a slot, it will re-emit the signal.

I do not wish to call the slot as a method right after the waitForReadyRead(), it just doesn't seem appropiate.

Maybe I actually need to re-implent the waitForReadyRead() to re-emit the signal?

Any ideas on this issue?

Additional info: waitForReadyRead() is returning true. I don't know if this is useful or not, but better safe than sorry.

^NyAw^
2nd November 2012, 11:34
Hi,

Why are you mixing blocking and non-blocking code? If you want to use a blocking code use only "waitForReadyRead" method.

alitoh
2nd November 2012, 13:04
Because this part of my application needs to be blocking. But not all of it.

Other than that, how would I be able to know when there is incoming data to the socket if I did not have the readyRead() signal connected to my slot?

^NyAw^
2nd November 2012, 13:29
Hi,

I recommend you to use the non-blocking method. You can wait to get the response on the slot connected to the "readyRead" signal. If you know how many bytes you are waiting or maybe a special end of message character.