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.
01-04-2013 12:28 PM
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?
Solved! Go to Solution.
01-04-2013 12:56 PM - edited 01-04-2013 01:06 PM
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.
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.
01-04-2013 01:11 PM - edited 01-04-2013 01:14 PM
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
01-04-2013 01:41 PM - edited 01-04-2013 01:42 PM
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.