So far my application works just fine. But there is one problem. We need to read the data from the serialport. This data may contain only bytes so reading with the readLine() function could give us false or no data. Here is the code now so you can understand my problem.
void MainWindow::readData()
{
while(serial->canReadLine())
{
QByteArray data = serial->readLine();
emit serialPortData(data, false);
QString myString(data);
if(myString.startsWith("SensorUpdate"))
emit sensorData(myString) ;
}
}
I am reading data and if it starts with a string ( some values ) I will send those values to another class where it will update a QTableWidget. But this "startsWith()" only works if I read line by line from the serial port. I want to use the readAll function and maybe store the chars until a new line is found or something like that. Can you help me?
Thanks!
In you GUI, you could split the QString into a list split on \n. Then loop the list and handle each as you normally would. So would not matter if u get more than one in as input.
This is what You had to do.
void SensorWidget::fillTable(QString serialString)
{
tempList = serialString.split("\r\n");
for(int i=0;i<tempList.size();i++)
{
//filll table code
}
}