I am trying to create QByteArray from std::vector.. I tried;
std::vector<uint8_t> buf;
QByteArray img = new QByteArray(reinterpret_cast<const char>(buf), buf.size());
However it gives error;
error: invalid cast from type 'std::vector<unsigned char, std::allocator<unsigned char> >' to type 'const char'
You need to cast buf.data()
instead of buf
:
QByteArray* img = new QByteArray(reinterpret_cast<const char*>(buf.data()), buf.size());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With