How to convert std :: vector <uint8_t> to QByteArray?

I am trying to create a QByteArray from std :: vector .. I tried;

std::vector<uint8_t> buf; QByteArray img = new QByteArray(reinterpret_cast<const char>(buf), buf.size()); 

However, this gives an error;

 error: invalid cast from type 'std::vector<unsigned char, std::allocator<unsigned char> >' to type 'const char' 
+6
source share
1 answer

You need to add buf.data() instead of buf :

 QByteArray* img = new QByteArray(reinterpret_cast<const char*>(buf.data()), buf.size()); 
+12
source

Source: https://habr.com/ru/post/989940/


All Articles