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.

inside custom component

Native Development

Reply
Developer
HuXu77
Posts: 196
Registered: ‎02-10-2011
My Device: Playbook 16GB and Z10
Accepted Solution

International MBCS

I have a music app that pulls in a users music files and some of the music songs have characters other than English characters and they show up all garbled.  Is there a way to have these characters automatically converted to their correct display?

 

For example e with an accent looks like A^%$% or something similar.

_________________________________________________
Apps
Go Music
Flashlight Fast Free/Pro
Fitbit for BlackBerry PlayBook
Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: International MBCS

If the data is in UTF8, then the following should work:

QString s = QString::fromUtf8(byteArray.constData(), byteArray.size());

 

Default QString constructor treats it as Latin1, but it's possible to change the default encoding on application level:

 

QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
HuXu77
Posts: 196
Registered: ‎02-10-2011
My Device: Playbook 16GB and Z10

Re: International MBCS


Zmey wrote:

If the data is in UTF8, then the following should work:

QString s = QString::fromUtf8(byteArray.constData(), byteArray.size());

 

Default QString constructor treats it as Latin1, but it's possible to change the default encoding on application level:

 

QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));

 


This worked perfectly!  I just had to make sure when saving a string to my sqlite DB that I do the 

 

QString s = QString::fromUtf8(byteArray.constData(), byteArray.size());

 

_________________________________________________
Apps
Go Music
Flashlight Fast Free/Pro
Fitbit for BlackBerry PlayBook
Please use plain text.