Why qDebug and plaintext gives different outputs?
-
Hello I'm kinda new in Qt and I'm working on gps data. My purpose is process the data that comes from gps.
connect(serial,&QSerialPort::readyRead,this,&MainWindow::serialReceived);
In sıgnal received slot, I'm printing the data in QPlainTextEdit gives me correct format of data.
void MainWindow::serialReceived() { QByteArray byteArray; byteArray = serial->readAll(); QString ba(byteArray); plainText->insertPlainText(ba); QTextCursor c = plainText->textCursor(); c.movePosition(QTextCursor::End); plainText->setTextCursor(c); }
But when I print with qDebug() it outputs:
"$GPGGA,102648.000,4059.7329,N,02"
"843.3850,E,2,7,1.67,82.3,M,39.5,"
"M,0000,000063\r\n$GPRMC,102648.00"
"0,A,4059.7329,N,02843.3850,E,0.0"
"3,290.70,050600,,,D6A\r\n"
"$GPGGA,102649.000,4059.7329,N,02"
"843.3850,E,2,7,1.67,82.3,M,39.5,"
"M,0000,000062\r\n$GPRMC,102649.00"
"0,A,4059.7329,N,02843.3850,E,0.0"
"5,290.70,050600,,,D6D\r\n"I need to get the data in the form of QPlainTextEdit shows so I can parse the data.
How can I achieve this ? Thanks. -
Hello I'm kinda new in Qt and I'm working on gps data. My purpose is process the data that comes from gps.
connect(serial,&QSerialPort::readyRead,this,&MainWindow::serialReceived);
In sıgnal received slot, I'm printing the data in QPlainTextEdit gives me correct format of data.
void MainWindow::serialReceived() { QByteArray byteArray; byteArray = serial->readAll(); QString ba(byteArray); plainText->insertPlainText(ba); QTextCursor c = plainText->textCursor(); c.movePosition(QTextCursor::End); plainText->setTextCursor(c); }
But when I print with qDebug() it outputs:
"$GPGGA,102648.000,4059.7329,N,02"
"843.3850,E,2,7,1.67,82.3,M,39.5,"
"M,0000,000063\r\n$GPRMC,102648.00"
"0,A,4059.7329,N,02843.3850,E,0.0"
"3,290.70,050600,,,D6A\r\n"
"$GPGGA,102649.000,4059.7329,N,02"
"843.3850,E,2,7,1.67,82.3,M,39.5,"
"M,0000,000062\r\n$GPRMC,102649.00"
"0,A,4059.7329,N,02843.3850,E,0.0"
"5,290.70,050600,,,D6D\r\n"I need to get the data in the form of QPlainTextEdit shows so I can parse the data.
How can I achieve this ? Thanks.Hi @fatihsezgin,
readAll()
does not care about line endings, so you get all data that has arrived at this point.You can try to use
canReadLine()
andreadLine()
(in a loop, as long ascanReadLine()
returns true), that should give you the lines you want.Regards
-
Hi @fatihsezgin,
readAll()
does not care about line endings, so you get all data that has arrived at this point.You can try to use
canReadLine()
andreadLine()
(in a loop, as long ascanReadLine()
returns true), that should give you the lines you want.Regards
@aha_1980 thank you :)