Qt calls setlocale(LC_ALL, "") because it is correct: every standard Unix program from cat when calling setlocale(LC_ALL, "") . The consequence of this call is that the language standard of the program is set to what is specified by the user. See the setlocale () man page:
When the main program starts, the portable locale "C" is selected by default. A program can be made portable for all locales by calling:
setlocale(LC_ALL, "");
after initializing the program ...
Given that Qt generates text to be read by the user and analyzes the input created by the user, it would be very unfriendly to refuse to let the user communicate with the user in their own language. Hence the call to setlocale ().
I hope that friendliness will be undeniable! The problem, of course, occurs when you try to analyze data files created by your program running under a different locale. Obviously, if you use the ad-hoc text format with a parser based on sscanf and friends, and not with the specified data format with a "real" parser, then this is a recipe for data corruption if it is done without taking into account the language settings. The solution is to: a) use a real serialization library that processes this material for you, or b) set the language for something specific (possibly "C") when writing and reading data.
If thread safety is a problem, then for modern POSIX implementations (or any Linux system with GNU version libc> = 2.3, which is pretty much βall of themβ at a given time), you can call uselocale() to set up a local local thread for all I / O operations. Alternatively, you can call _l versions of regular functions that take a locale object as an additional argument.
Will everything break if you call setlocale(LC_ALL, "C"); ? No, but itβs correct for the user to set the locale that they prefer and either save your data in a well-defined format or indicate the language in which your data should be read and written at run time.
source share