I am writing a Qt/C++ program which receives data from a socket. I found that I was losing the readyRead signal because my slot was taking too long to analyze the incoming data. So now I've paired it down to the minimum:
void test::inputAvailable()
{
while (m_tcpSocket->bytesAvailable())
m_inputBuffer += m_tcpSocket->readAll();
emit(datawaiting());
}
My questions are:
- Do I need to protext the m_inputBuffer variable with a mutex? Since this slot will be appending to it, while my main program may be removing data from it.
- Would a mutex slow down my slot too much since I need it to be quick. (to avoid losing a readyRead signal)
- Is the emit (last line) the right way to signal my program to analyze the incoming data? Or does this cause my program to re-enter the event loop while still in the slot (causing a signal to be lost)
I've read this similar question but no one has given a real answer.