Issue
How can I find the currently active QLocale
? We can find the default system locale with QLocale.system()
, but I want something like QLocale.current()
, to check if the locale changes I am trying to make are actually working.
The documentation has lots of methods for setting locales, or finding the properties of a given QLocale
. But is there a simple method to return the current QLocale
, so that I can then apply these methods to it (e.g., name()
)?
Related questions
Solution
The answer is to simply use:
current_locale = QtCore.QLocale()
This will resolve to the system locale, unless the default locale has been explicitly re-set using QLocale.setDefault()
.
So the normal procedure would be: if necessary, set the default locale immediately after the QApplication
is created. After that, any time a QLocale
object is created with no arguments, it will either resolve to the locale you originally set yourself, or fall back to the system locale.
This seems to imply that it is best to always construct a new QLocale
object to obtain information about the locale, rather than caching the information for later re-use.
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.