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
Posts: 122
Registered: ‎11-12-2010
My Device: Dev Alpha
My Carrier: N/A
Accepted Solution

Obtaining a currency symbol

Hi again

 

I am building a BB10 app using cascades and qml but I need to use a tiny bit of C++ (which I havent used for many many years).

 

What im trying to do is obtain the devices Currency Symbol. So this is what I did:

 

I created a c++ function in app.cpp as follows:

 

char const * app::getCurrencySymbol() {

  QLocale cs;
  return (cs.currencySymbol().toUtf8().data());
}

 in my qml I use as follows (for a test I but this on a button click:

 

onClicked: {
  lbTest.text = app.getCurrencySymbol();
}

 but 'undefined' gets displayed on the label.

 

I'm pretty sure the issue is with my c++ because if I change my function to return say a double, the value shows on the label.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Obtaining a currency symbol

JavaScript supports Unicode, so you could just use whatever Unicode escape was appropriate.  For example, to generate the Euro currency sign, you'd do lbTest.text = "\u20AC".

 

Whether a given symbol exists in a given font is a different question, of course, but you can easily experiment.  The standard font should have just about everything you're likely to want.

 

You can search for the appropriate codes at places like http://www.fileformat.info/info/unicode/char/search.htm


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 122
Registered: ‎11-12-2010
My Device: Dev Alpha
My Carrier: N/A

Re: Obtaining a currency symbol

Hi Peter and thanks for your quick reply.  The trouble is I need to pick up the devices currency symbol. For example, in good ol java I could have done:

 

String x = Locale.getDefaultForSystem().toString();

 which would have returned en_gb or en_us, fr etc etc. From this I could then set the correct currency symbol.

Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Obtaining a currency symbol

QLocale().name() returns the equivalent of your java example there, and have you tried making your getCurrencyMethod() return a QString? I had thought that that is what the QML system supported, didnt think it supported char *
Like all of my posts
Developer
Posts: 122
Registered: ‎11-12-2010
My Device: Dev Alpha
My Carrier: N/A

Re: Obtaining a currency symbol

Thanks Kyle, returning a QString did the trick.