Backto you guys with another annoying problem that i can't solve. Topic is the same so i didnt feel the need to create a new one.
Case scenarios is as follows. After i read the data as solved in yesterday's post, i need to use endianess to show the correct value on my UI. I do this using:
const int horizontal = qFromLittleEndian<qint16>(reswidth.data())
const int horizontal = qFromLittleEndian<qint16>(reswidth.data())
To copy to clipboard, switch view to plain text mode
Now, using my ui controls, i change the value and i need to write it back to my binary file using this piece of code:
int width_int = width->value();
QFile settings
("example.dat");
fileData.replace(0x0000000C,2, hex1);
settings.seek(0);
settings.write(fileData);
settings.flush();
settings.close();
qDebug() << hex1;
int width_int = width->value();
QString width_string = QString::number(width_int, 16);
QFile settings("example.dat");
settings.open(QIODevice::ReadWrite);
QByteArray fileData(settings.readAll());
QByteArray hex1 = QByteArray::fromHex(width_string.toLatin1());
fileData.replace(0x0000000C,2, hex1);
settings.seek(0);
settings.write(fileData);
settings.flush();
settings.close();
qDebug() << hex1;
To copy to clipboard, switch view to plain text mode
On my binary file, it writes "02 80" but i want "80 02". Same for qDebug output ""\x02\x80" but i want to swap bytes on writing and the ouput to be "\x80\x02".
I know it's all about endianess but i don't know how to properly implement it into my code..
*Note width->value(); is a value from QSpinBox.
Thanks in advance!
Bookmarks