I am writing a function to communicate with a test server that I didn't write. I send a command, and need to immediately capture the multi-line response before doing anything else. Of course, I'd like to not block my whole UI, which shouldn't be a problem as the response is only a few nominal ms behind when I send the command.
That being said, this is what I've come up with:
QByteArray MainWindow::ask(const QByteArray &cmd) //blocking function. Add to thread while in use?
{
this->consoleWindow->put_data_in_console(cmd);
this->socket->write(cmd + "\r\n");
QByteArray resBuffer;
socket->waitForReadyRead();
while(socket->bytesAvailable > 0)
{
resBuffer.append(socket->readAll());
}
return resBuffer;
}
But I'm only able to capture the first line of my four-line response.
Thanks in advance!