Solved Raw data conversion using (?) QByteArray
-
Hello,
is there any built-in-qt mechanism to perform such convesion(s)?char raw_bytes[4] = {0x00, 0x00, 0xff, 0xff}; QByteArray byte_array = QByteArray::fromRawData(raw_bytes, 4); byte_array.toInt(); // <- i wanted it to return 65535 but result is 0
-
You're almost there:
char raw_bytes[4] = {0x00, 0x00, 0xff, 0xff}; QByteArray byte_array = QByteArray::fromRawData(raw_bytes, 4); QDataStream in(&byte_array, QIODevice::ReadOnly); quint16 value; in >> value; // First 2 bytes, gives 0 in >> value; // Second 2 bytes, 65535
-
Hi!
char raw_bytes[4] = {0x00, 0x00, 0xff, 0xff}; QByteArray byte_array = QByteArray::fromRawData(raw_bytes, 4); QDataStream stream(byte_array); int result; stream >> result; qDebug() << result; // 65535
Cheers!
-
@kshegunov Ninja!
-
Alright, I think this one can do. Thank you both!