我正在尝试从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'
.data()
只在 C++11 及其以后的版本中可用。如果你的编译器不支持这个函数,可以使用&buf[0]
。 - Saul