我正在尝试从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'
答案 0 :(得分:13)
您需要投射buf.data()
而不是buf
:
QByteArray* img = new QByteArray(reinterpret_cast<const char*>(buf.data()), buf.size());