PDA

View Full Version : save variable size hex string into uchar array



amika
26th October 2011, 09:01
Suppose that I have a number in hexadecimal notation
with size 2n, like "aa00F234AA". I want to write it in
an unsigned char array of size n ("aa" in the first
byte, "00" in the second byte, etc) . In fact I want a
function like this


void f(unsigned char* dest, QString str);

How can I do this?
Can I use QByteArray::fromHex()
Thanks in advance.

ChrisW67
26th October 2011, 22:35
Yes, use QByteArray::fromHex() and then copy QByteArray::size() bytes out of the QByteArray::constData() buffer into your (preallocated) dest buffer using memcpy() or whatever.

The question remains; do you really want to mix managed memory with the unmanaged C-style malloced blocks and pointers?