本文介绍了QByteArray 与无符号字符之间的转换 *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QByteArray inArray = " ... ";
unsigned char *in = convert1(inArray);
unsigned char *out;
someFunction(in, out);
QByteArray outArray = convert2(out);

问题是我怎样才能正确地进行这些转换(convert1 和 convert2).我无法更改 someFunction(unsigned char *, unsigned char *),但我必须在这里使用 QByteArray.

the question is how can I correctly make these conversions (convert1 and convert2).I cannot change someFunction(unsigned char *, unsigned char *), but I have to work with QByteArray here.

推荐答案

Qt 真的很棒 文档,你应该使用它们.

Qt has really great docs, you should use them.

如果 someFunction 没有修改或存储指向数据的指针,你可以使用这个:

If someFunction doesn't modify or store pointer to in data you can use this:

QByteArray inArray = " ... ";
unsigned char *out;
someFunction((unsigned char*)(inArray.data()), out);
QByteArray outArray((char*)out);

否则,您必须制作 QByteArray::data() 返回的 char* 的深层副本(请参阅代码片段的文档).

Otherwise you have to make a deep copy of the char* returned by QByteArray::data() (see the docs for code snippet).

这篇关于QByteArray 与无符号字符之间的转换 *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 11:04