I am reading information from a serial port. How do I wait for a newline to come in, and then deal with the data? That is, how do I make sure I'm chunking a whole line at a time.
This code does not work:
void MainWindow::readData()
{
QByteArray data = serial->readAll(); //reads in one character at a time (or maybe more)
console->putData(data);
charBuffer.append(data);
if (data.contains("\n")) //read into a structure until newline received.
{
//call parsedata
sensorValues->parseData(charBuffer); //send the data to be parsed.
//empty out the structure
charBuffer = "";
}
}
Let's say the serial port sends "Sensor1 200\n".
data might contain the following: "Se" then "n", "sor 2"