Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Contributor
actjak
Posts: 33
Registered: ‎05-02-2012
My Carrier: bouyig

utf-8 in CASCAD

[ Edited ]

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 éä"

Please use plain text.
Developer
soaman
Posts: 610
Registered: ‎03-03-2011
My Carrier: Mobitel

Re: utf-8 in CASCAD

QString x(text2); // create qstring from qbytearray
cout << x.toUtf8().constData() << endl; // output as UTF-8
--------------------------------------------------------

Follow our developer blog on Slovenia BlackBerry Developer Group!
Please use plain text.
Contributor
actjak
Posts: 33
Registered: ‎05-02-2012
My Carrier: bouyig

Re: utf-8 in CASCAD

 

thank you for the reply , I tried and I found

 

"Return message éä" 

 

hat which is not the result hoped

 

Please use plain text.
BlackBerry Development Advisor
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Carrier: developer

Re: utf-8 in CASCAD

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

Please use plain text.
BlackBerry Development Advisor
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Carrier: developer

Re: utf-8 in CASCAD

Did you resolve your issue?

 

Stuart

Please use plain text.
Contributor
actjak
Posts: 33
Registered: ‎05-02-2012
My Carrier: bouyig

Re: utf-8 in CASCAD

no I have not solved the problem

the character are expected:

 

 

"Return message éä" 

Please use plain text.
BlackBerry Development Advisor
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Carrier: developer

Re: utf-8 in CASCAD

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();


 

Please use plain text.
BlackBerry Development Advisor
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Carrier: developer

Re: utf-8 in CASCAD

Did this lead to a solution?

 

Stuart

Please use plain text.