Hello,
I have a char* that holds 256 chars. I can not convert it to QByteArray. My char* contains following data: 0xff, 0xff, 0xff, 0xff, 0xaa, 0x99, 0x55, 0x66, 0x31, 0x61, 0x00, 0x00, 0x32, 0x81,.....
char *data = (char *)malloc(256 * sizeof(char));
FLASH_ReadCalibration(CALIBRATION_ADDR, data);
b1
= QByteArray::fromRawData((const char*)data,
sizeof(data
));
b2
= QByteArray(reinterpret_cast<const
char*>
(data
),
sizeof(data
));
emit updateData(ByteData);
QByteArray b1, b2;
char *data = (char *)malloc(256 * sizeof(char));
FLASH_ReadCalibration(CALIBRATION_ADDR, data);
b1 = QByteArray::fromRawData((const char*)data, sizeof(data));
b2 = QByteArray(reinterpret_cast<const char*>(data), sizeof(data));
emit updateData(ByteData);
To copy to clipboard, switch view to plain text mode
b1 and b2 contain only 4 bytes: 0xff, 0xff, 0xff, 0xff
What is wrong with my code?
Thanks.
Added after 25 minutes:
I have found it. sizeof(data) returns 4, although data contains 256 chars.
This worked: b1 = QByteArray::fromRawData((const char*)data, 256);
Bookmarks