Hello,

I have an issue when I try to read an HEX document and store the content into a QByteArray. What I want to get is a QByteArray with HEX content and show the content in a LineEdit.

I works for almost perfect but is not working when one byte is "0x0d" (\r). ¿Which is the correct conversion type when reading the file to an HEX QByteArray?


Qt Code:
  1. QFile file(ui->lineEdit_FilePath->text().toLatin1());
  2.  
  3. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
  4. return;
  5.  
  6. ui->lineEditSize->setText(QString::number(file.size()));
  7.  
  8. QTextStream fileTextStream(&file);
  9.  
  10. QByteArray contentHex = fileTextStream.readAll().toLocal8Bit());
  11.  
  12. ui->lineEdit_1->setText(contentHex.mid(0,4).toHex());
To copy to clipboard, switch view to plain text mode 


I also tried doing this:

Qt Code:
  1. QString content = fileTextStream.readAll();
  2. QByteArray contentHex = content.toLatin1().toHex();
To copy to clipboard, switch view to plain text mode 

In this case I had a problem when reading values upper than 0x7f but I solved it using ".toLocal8Bit()" but now the problem is with "0x0d" byte values.



Thanks in advance.