Localized number format [answered]
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
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.
https://github.com/mikelima/quantofa/blob/master/src/quantofa.cpp
mikelima ( 2014-02-21 13:15:39 +0200 )editTrivia - Swedish uses comma too.
vattuvarg ( 2014-02-21 21:48:57 +0200 )editStill 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 +0200 )editUhm... 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 +0200 )edit