Skip to content

Commit ca185cf

Browse files
doc: Document differences in bitcoind and bitcoin-qt locale handling
1 parent 4430744 commit ca185cf

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/qt/bitcoin.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ BitcoinApplication::BitcoinApplication(interfaces::Node& node):
201201
returnValue(0),
202202
platformStyle(nullptr)
203203
{
204+
// Qt runs setlocale(LC_ALL, "") on initialization.
204205
RegisterMetaTypes();
205206
setQuitOnLastWindowClosed(false);
206207
}

test/lint/lint-locale-dependence.sh

+33
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,39 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
export LC_ALL=C
7+
8+
# Be aware that bitcoind and bitcoin-qt differ in terms of localization: Qt
9+
# opts in to POSIX localization by running setlocale(LC_ALL, "") on startup,
10+
# whereas no such call is made in bitcoind.
11+
#
12+
# Qt runs setlocale(LC_ALL, "") on initialization. This installs the locale
13+
# specified by the user's LC_ALL (or LC_*) environment variable as the new
14+
# C locale.
15+
#
16+
# In contrast, bitcoind does not opt in to localization -- no call to
17+
# setlocale(LC_ALL, "") is made and the environment variables LC_* are
18+
# thus ignored.
19+
#
20+
# This results in situations where bitcoind is guaranteed to be running
21+
# with the classic locale ("C") whereas the locale of bitcoin-qt will vary
22+
# depending on the user's environment variables.
23+
#
24+
# An example: Assuming the environment variable LC_ALL=de_DE then the
25+
# call std::to_string(1.23) will return "1.230000" in bitcoind but
26+
# "1,230000" in bitcoin-qt.
27+
#
28+
# From the Qt documentation:
29+
# "On Unix/Linux Qt is configured to use the system locale settings by default.
30+
# This can cause a conflict when using POSIX functions, for instance, when
31+
# converting between data types such as floats and strings, since the notation
32+
# may differ between locales. To get around this problem, call the POSIX function
33+
# setlocale(LC_NUMERIC,"C") right after initializing QApplication, QGuiApplication
34+
# or QCoreApplication to reset the locale that is used for number formatting to
35+
# "C"-locale."
36+
#
37+
# See https://doc.qt.io/qt-5/qcoreapplication.html#locale-settings and
38+
# https://stackoverflow.com/a/34878283 for more details.
39+
740
KNOWN_VIOLATIONS=(
841
"src/bitcoin-tx.cpp.*stoul"
942
"src/bitcoin-tx.cpp.*trim_right"

0 commit comments

Comments
 (0)