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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 194
Registered: ‎11-24-2012
My Device: Dev Alpha B, Bold 9700
My Carrier: NA
Accepted Solution

help understanding localization and fromUtf8 method

I create share data like this:

QString data = QString::fromUtf8(tr("some localized string"));
query->setData(data.toUtf8());

 Why do the examples show fromUtf8 / toUtf8 when many of the languages I support need Utf16? Is it okay to use Utf16 or will something happen I'm not aware of?

 

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: help understanding localization and fromUtf8 method

[ Edited ]

UTF8 was created for backwards compatibility with ASCII and lower 7 bits match ASCII encoding. It can be used with std C functions like strlen() without any conversion.

In UTF8 one character can take up to 6 bytes and it's capable of storing all characters UTF16 can store.

Source code files are usually created in UTF8, but QString uses UTF16 internally, that's why fromUtf8 conversion is needed.

 

p.s.

For network communication UTF8 is usually better because it doesn't depend on byte order.

Byte order for UTF16 can depend on HW architecture. Also UTF16 text sometimes has BOM (byte order marker) prepended to assist in determining the byte order of the characters. UTF8 doesn't require it.

 

One of UTF16 advantages is memory usage: UTF8 can take 3 bytes per character for non-ASCII text while UTF16 uses 2 most of the time.

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 194
Registered: ‎11-24-2012
My Device: Dev Alpha B, Bold 9700
My Carrier: NA

Re: help understanding localization and fromUtf8 method

[ Edited ]

Can I skip the conversion with BB 10 when using it in my sharing method?

Highlighted
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: help understanding localization and fromUtf8 method

[ Edited ]

If function expects const char * or ByteArray and encoding isn't specified then most likely it expects UTF8-encoded string. It should be zero-terminated in case of const char *.

 

I've used UTF8 strings in InvokeActionItem for BBM sharing and non-ascii characters were displayed correctly.

 

QString data = QString::fromUtf8("text");
query->setData(data.toUtf8()); // setData expects ByteArray

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 194
Registered: ‎11-24-2012
My Device: Dev Alpha B, Bold 9700
My Carrier: NA

Re: help understanding localization and fromUtf8 method

My biggest concern is East Asian Languages, which require UTF 16.  Have you tried any of those characters with a InvokeAction?

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: help understanding localization and fromUtf8 method

[ Edited ]

I've enabled Chinese input in language settings. Text I typed in application was passed unchanged into BBM so it seems to work. UTF8 is capable of representing the entire characters range.


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 194
Registered: ‎11-24-2012
My Device: Dev Alpha B, Bold 9700
My Carrier: NA

Re: help understanding localization and fromUtf8 method

Thank you once again Zmey!