如何将std :: vector <uint8_t>转换成QByteArray?

时间:2015-06-29 10:53:27

标签: c++ qt vector qbytearray

我正在尝试从std :: vector创建QByteArray。我试过;

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

然而它给出了错误;

error: invalid cast from type 'std::vector<unsigned char, std::allocator<unsigned char> >' to type 'const char'

1 个答案:

答案 0 :(得分:13)

您需要投射buf.data()而不是buf

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