Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'
like image 646
goGud Avatar asked Jun 29 '15 10:06

goGud


1 Answers

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

QByteArray* img = new QByteArray(reinterpret_cast<const char*>(buf.data()), buf.size());
like image 177
m.s. Avatar answered Sep 16 '22 22:09

m.s.