我试图从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'
解决方法
你需要转换buf.data()而不是buf:
QByteArray* img = new QByteArray(reinterpret_cast<const char*>(buf.data()),buf.size());