Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QByteArray convert to/from unsigned char *

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

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.

like image 291
Eddie Avatar asked Jan 20 '12 10:01

Eddie


1 Answers

Qt has really great docs, you should use them.

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);

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

like image 171
chalup Avatar answered Sep 20 '22 22:09

chalup