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
Regular Contributor
Guillaume_LACHAUD
Posts: 60
Registered: ‎12-19-2012
My Device: BB10 Alpha B
My Carrier: SFR
Accepted Solution

Character encoding issues but only in c++

Hi !

 

My project is set to use UTF-8 encoding in all its files. I have a Label defined in qml. When I set its text property from the QML file, I have no issue with charcters such as "è". But with the same text, hard-coded in C++, the chracter is miswritten.

 

Any ideas ?

Please use plain text.
Developer
tonygluk
Posts: 30
Registered: ‎11-06-2012
My Device: BB 10 Dev Alpha
My Carrier: MegaFon

Re: Character encoding issues but only in c++

Hello!

 

Please try 

QString::fromUtf8("your text");
Please use plain text.
Developer
Developer
klz
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook
My Carrier: MTS Ukraine

Re: Character encoding issues but only in c++

Unfortunately this is not working for DropDown, or I am doing something wrong. 

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com
Please use plain text.
Developer
Zmey
Posts: 1,509
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Character encoding issues but only in c++

The following works for me:

 

dropDown->add(Option::create()
	.value(123)
	.text(QString::fromUtf8("put UTF8 text here"))
	.selected(YES));

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
tonygluk
Posts: 30
Registered: ‎11-06-2012
My Device: BB 10 Dev Alpha
My Carrier: MegaFon

Re: Character encoding issues but only in c++

Could you post a short example of what you're doing with DropDown along with the string you're trying to use?

Please use plain text.
Developer
Developer
klz
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook
My Carrier: MTS Ukraine

Re: Character encoding issues but only in c++

Hey tonygluk and everyone else,

 

So basically my code is 

 

ddSecond->add(Option::create().text(QString::fromUtf8("RME_Estado de México")));

 And this is a result http://gyazo.com/1c544a96b29a9174b04962b3cf67bfe1

 

 

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com
Please use plain text.
Developer
tonygluk
Posts: 30
Registered: ‎11-06-2012
My Device: BB 10 Dev Alpha
My Carrier: MegaFon

Re: Character encoding issues but only in c++

I'm a bit confused because I tried to use 

QString::fromUtf8("RME_Estado de México")

as a title of my TitleBar and this works perfectly in my case.

My encoding settings (in Qt Creator):

Default encoding: UTF-8
UTF-8 BOM: Keep If Already Present

 

You could also try to substitute é with \u00e9, i.e.

QString::fromUtf8("RME_Estado de M\u00e9xico")
Please use plain text.
Developer
Developer
klz
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook
My Carrier: MTS Ukraine

Re: Character encoding issues but only in c++

For title of TitleBar it works properly for me even without convertation fromUtf8.

 

This one

QString::fromUtf8("RME_Estado de M\u00e9xico")

 Works well, thank you! But another problem is that I'm getting the data dinamicaly from a server. Is there an easy way to replace é with \u00e9?

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com
Please use plain text.
Developer
Zmey
Posts: 1,509
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Character encoding issues but only in c++

If this works then it looks like the .cpp file is not in UTF-8 encoding... Do you set TitleBar's title in the same .cpp file?

If dynamic data is in UTF8 then there's probably no need to replace anything.

Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
Developer
klz
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook
My Carrier: MTS Ukraine

Re: Character encoding issues but only in c++

Ah, my bad. I set the title directly in QML. Okay, will check encoding. Thanks a lot! 

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com
Please use plain text.