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?
QFile file(ui
->lineEdit_FilePath
->text
().
toLatin1());
return;
ui
->lineEditSize
->setText
(QString::number(file.
size()));
QByteArray contentHex
= fileTextStream.
readAll().
toLocal8Bit());
ui->lineEdit_1->setText(contentHex.mid(0,4).toHex());
QFile file(ui->lineEdit_FilePath->text().toLatin1());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
ui->lineEditSize->setText(QString::number(file.size()));
QTextStream fileTextStream(&file);
QByteArray contentHex = fileTextStream.readAll().toLocal8Bit());
ui->lineEdit_1->setText(contentHex.mid(0,4).toHex());
To copy to clipboard, switch view to plain text mode
I also tried doing this:
QString content
= fileTextStream.
readAll();
QByteArray contentHex
= content.
toLatin1().
toHex();
QString content = fileTextStream.readAll();
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.
Bookmarks