In my program, I work a lot with serial communication, so QByteArray used very often.
I was wondering if there was a shorter way to initialize a QByteArray specific bytes than:
const char test_data[] = { static_cast<char>(0xB1), static_cast<char>(0xB2), 0x5, static_cast<char>(0xFF), static_cast<char>(0xEE), static_cast<char>(0xEE), static_cast<char>(0x0)};
static_cast<char> necessary because otherwise C ++ 11 gives a narrowing error because the range from 0x7F to 0xFF is greater than a char can match - but a char is what the QByteArray constructor asks.
The constructor of QByteArray :
QByteArray::QByteArray(const char *data, int size = -1)
source share