我正在尝试从 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());
关于c++ - 如何将 std::vector<uint8_t> 转换为 QByteArray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31113857/