c++ - 如何将 std::vector<uint8_t> 转换为 QByteArray?

标签 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'

最佳答案

您需要转换 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/

相关文章:

.net - XNA 沿 2D 直线运动

java - 如何从高程栅格近似 vector 等高线?

c++ - 在安全浏览器 7 (Firefox 29) 上构建失败

c++ - 如何在 Eclipse CDT 中启用 C++11/C++0x 支持?

c++ - QGLWidget 拒绝绘制任何东西

c++ - Linux 共享库被加载两次

c++ - 如何验证是否选中了多个复选框

c++ - template specialization中的type会继续计算吗?

c++ - 断言、异常、运行时错误或未定义行为?

r - 如何根据引用向量找到元素的位置(索引)?