We have moved to a new Sailfish OS Forum. Please start new discussions there.

Localized number format [answered]

asked 2014-02-20 22:10:08 +0300

thwint gravatar image

Hi, I have written an a pure QML application. So far it is working well. Unfortunately there is a problem with the input of formatted numbers.

Im using the following inputMethodHints and want to have a decimal value. inputMethodHints: Qt.ImhFormattedNumbersOnly

Most of the locales are using a . as decimal sign, but Germany (others as well?) are using a , as decimal point.

Now I want to find out which locale is currently set to use it with Number.fromLocaleString. On the SailfishOS Emulator as well as on my phone Qt.locale() always gives me a "C" locale instead of whatever locale is set.

Is there another way to find out the current locale or to parse decimal values? It should be possible to use 10,5 as well as 10.5

Thanks for any help

edit retag flag offensive reopen delete

The question has been closed for the following reason "the question is answered, an answer was accepted" by thwint
close date 2014-02-26 13:17:57.283974


Qt.locale().decimallSign works for me...

But my apps have a slightly edited main. to load the localized translation. I don't think it should matter, but I cannot verify this for now.


mikelima ( 2014-02-21 13:15:39 +0300 )edit

Trivia - Swedish uses comma too.

vattuvarg ( 2014-02-21 21:48:57 +0300 )edit

Still no success. Also QString locale = QLocale::system().name(); always returns a "C" locale. When opening the input dialog with Qt.ImhFormattedNumbersOnly the returned value contains a , e.g. 10,5, because the locale is set to "C" instead of "de_DE" When I use Number.fromLocaleString I always get the following error. Error: Locale: Number.fromLocaleString(): Invalid format It works on any locale which has a . as decimal separator.

thwint ( 2014-02-22 13:25:29 +0300 )edit

Uhm... Did you try launching your application from the phone? Because, actually, now that I think of it, if you start it from the sdk, you get the c locale. But if you start from the launcher, it should work.

  • List item
mikelima ( 2014-02-22 19:03:17 +0300 )edit

1 Answer

Sort by » oldest newest most voted

answered 2014-02-24 20:09:30 +0300

thwint gravatar image

Thx. That was the issue. When starting from the mobil I get the correct locale. Now I can go further with the development.

edit flag offensive delete publish link more

Question tools

1 follower


Asked: 2014-02-20 22:10:08 +0300

Seen: 612 times

Last updated: Feb 20 '14