07-31-2012 04:14 AM - edited 07-31-2012 04:15 AM
Hello;
I want to convert a Base64 String to UTF-8
my code is :
QByteArray text2 = QByteArray::fromBase64("UmV0dXJuIG1lc3NhZ2Ugw6nDpA ==");
QString textok = text2;
qWarning() <<"le message: " <<textok.toUtf8();I get : "Return message éä"
but I would get : "Return message éä"
07-31-2012 11:50 AM
08-01-2012 05:17 AM
thank you for the reply , I tried and I found
"Return message éä"
hat which is not the result hoped
08-07-2012 12:54 PM
Are you getting console messages:
'ascii' codec can't encode characters in position 15-18: ordinal not in range(128)
What characters are you expecting to see?
Stuart
08-15-2012 10:43 AM
Did you resolve your issue?
Stuart
08-15-2012 11:31 AM
no I have not solved the problem
the character are expected:
"Return message éä"
08-15-2012 01:49 PM
Did some playing, with code somewhat like below.
QByteArray::fromBase64 doesn't do anything in the way of error checking. I think it's running off the end of the input string.
What string are you trying to encode into base64? Try explicitly encoding it and see what you get:
QByteArray b5("Return message ");
qDebug() << b5.toBase64();
Stuart
=======================
//QByteArray b1("UmV0dXJuIG1lc3NhZ2Ugw6nDpA");
QByteArray b1("UmV0dXJuIG1lc3NhZ2U=");
qDebug() << "b1: " << b1.length() << " " << b1;
QByteArray b2 = QByteArray::fromBase64(b1);
qDebug() << "b2: " << b2.length() << " " << b2;
QString s1 = b2;
qDebug() << "s1: " << s1.length() << " " << s1;
qDebug() << "s1data" << *s1.data();
QByteArray b3("UmV0dXJuIG");
qDebug() << "b3: " << b3.length() << " " << b3;
QByteArray b4 = QByteArray::fromBase64(b3);
qDebug() << "b4: " << b4.length() << " " << b4;
QString s2 = b4;
qDebug() << "s2: " << s2.length() << " " << s2;
qDebug() << "s2data" << *s2.data();
QByteArray text = QByteArray::fromBase64("UXQgaXMgZ3JlYXQh");
qDebug() << text.data(); // returns "Qt is great!"
QByteArray b5("Return message ");
qDebug() << b5.toBase64();
08-21-2012 04:33 PM
Did this lead to a solution?
Stuart