3

How can I write data from unsigned char* buffer to QDatastream. Threre are methods writeBytes and writeRawData. But they accept const char*. Can I use unsigned char* for it?

1 Answer 1

5

You can just cast to const char*

unsigned char array[] =  {1,2,3,4,5};
QByteArray ba;
QDataStream datastream(&ba,QIODevice::ReadWrite);
datastream.writeRawData((const char*) array,5);
Sign up to request clarification or add additional context in comments.

2 Comments

Wont it affect on data in buffer?
no, a pointer is just a memory address. the command above will copy the 5 bytes verbatim from that memory address. You need to be careful when you read those bytes out of the buffer that you cast the pointer back to an unsigned char.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.