Hello all,
I have an application that is receiving data over serial using QtSerialPort that is displaying data over a terminal (much like the examples in QtSerialPort if you are familiar with it). I also want to be able to save this data into a .txt file for further analysis. My problem is that I'm using QDataStream and it seems to be I am inserting extra characters somehow.
For example, data coming over the terminal, and how it's supposed to
1, 3, 2500000, 100000, 23000000
but when I'm saving to a .txt file the data is saved as:
> 1 , 3 , 2 5 0 0 0 0 0 , 1 0 0 0 0 0 , 2 3 0 0 0 0 0 0
And yes, there's an extra ">" at the beginning
Soooo here's my code. Here is to setup the save file:
void MainWindow::on_pushButton_clicked()
{
//Savefile setup
if(ui->lineEdit_savefile->text().isEmpty()) on_pushButton_Browse_clicked(); //Check to make sure the user entered a file
QString fileName
= ui
->lineEdit_savefile
->text
();
if(!fileName.endsWith('.txt')){
fileName.append(".txt");
ui->lineEdit_savefile->setText(ui->lineEdit_savefile->text().append('.txt'));
}
saveFile.setFileName(fileName);
QMessageBox::information(this, tr
("Unable to open file"),
saveFile.errorString());
return;
}
}
void MainWindow::on_pushButton_clicked()
{
//Savefile setup
if(ui->lineEdit_savefile->text().isEmpty()) on_pushButton_Browse_clicked(); //Check to make sure the user entered a file
QString fileName = ui->lineEdit_savefile->text();
if(!fileName.endsWith('.txt')){
fileName.append(".txt");
ui->lineEdit_savefile->setText(ui->lineEdit_savefile->text().append('.txt'));
}
saveFile.setFileName(fileName);
if(!saveFile.open(QIODevice::WriteOnly | QIODevice::Text)){
QMessageBox::information(this, tr("Unable to open file"),
saveFile.errorString());
return;
}
}
To copy to clipboard, switch view to plain text mode
Here is how I write to the file:
void MainWindow
::saveData(const QByteArray &data
){ }
void MainWindow::saveData(const QByteArray &data){
QDataStream out(&saveFile);
out.setVersion(QDataStream::Qt_4_5);
out << QString(data);
}
To copy to clipboard, switch view to plain text mode
And this is how the console application handles the data and prints it to the screen. It works correctly.
{
bar->setValue(bar->maximum());
}
void Console::putData(const QByteArray &data)
{
insertPlainText(QString(data));
QScrollBar *bar = verticalScrollBar();
bar->setValue(bar->maximum());
}
To copy to clipboard, switch view to plain text mode
How do I get rid of these extra characters? Thank you very much in advance for your input(s)!
Bookmarks