How to Convert Data to/from Base64 in Qt

Posted on Posted in Qt Tutorials, Tutorials

Qt Framework implements many convenience functions inside QByteArray for quickly handling of raw data. One of the widely used encoding methods is Base64 and if you’re with Qt, you can easily convert any string (QString) to/from Base64.

Below is an example code that shows how to convert data stored in a QByteArray to Base 64.

As you can see below, toBase64 function is used for converting to Base64 and fromBase64 can be used to converting Base64 to a readable string.

QByteArray b;
b = “”;
QByteArray b64 = b.toBase64();
qDebug() << b64; // “aHR0cDovL2FtaW4tYWhtYWRpLmNvbQ==”
qDebug() << QByteArray::fromBase64(b64); // “”

Leave a Reply

Your email address will not be published. Required fields are marked *