How to convert a QByteArray to std::array<unsigned char, 33UL>?
Solved
General and Desktop
-
See https://en.cppreference.com/w/cpp/container/array on how to iterate over an std::array<> (see examples). Therefore you can also append the bytes to a QByteArray.
-
Would that be a possible way to do it?
template<class T> T ByteArrayToStdArray(const QByteArray &byteArray) { T stdArray; //qDebug() << "std::array size" <<stdArray.size(); for (unsigned int i = 0; i < stdArray.size() && i < (unsigned int) byteArray.size(); i++) { stdArray[i] = (unsigned char) byteArray.at(i); } return stdArray; }
-
Since it's a simply C array:
std::array<unsigned char ,33UL> myArray; myArray[0] = 1;