is this right ?
No. A QByteArray is created empty with no size, so accessing text[ i ] on an empty array will cause a crash. Do this:

Qt Code:
  1. QByteArray text64 = QByteArray::fromRawData( pointer_to_buffer, len_of_my_buffer ).toBase64();
  2. create_xml_function( text64, "encoded_data" ); // spaces not allowed in XML tags!
To copy to clipboard, switch view to plain text mode 

Of course, you will want to add some error checking...