c++ - Getting country code for QLocale::Country -
i trying find country code given qlocale::country value. in manual have found function, similar: qlocale::name.
qstring qlocale::name () const
returns language , country of locale string of form "language_country", language lowercase, two-letter iso 639 language code, , country uppercase, two- or three-letter iso 3166 country code.
the second part of return value need, have constructed following function:
qstring getcountrycode(qlocale::country c) { return qlocale(qlocale::anylanguage, c).name().split('_').at(1).tolower(); }
strangely enough, if call function following way:
qdebug() << getcountrycode(qlocale::canada);
it produce output:
"us"
i have expected "ca"! on other hand, if call like:
qdebug() << getcountrycode(qlocale::hungary);
then produce correct answer:
"hu"
what missing here? (i using qt 5.2)
in general, given feature want isn't directly available, please submit feature request on bugtracker.
apart that, you can't build qlocale object anylanguage
. makes absolutely no sense -- qlocale object identifies specific locale. 1 should pick canada, fr_ca
or en_ca
?
solution: use
qlist<qlocale> locales = qlocale::matchinglocales(qlocale::anylanguage, qlocale::anyscript, qlocale::canada);
then take first of list (if exists) , extract country name doing.
Comments
Post a Comment