gpt4 book ai didi

qt - Qt 是否强制系统语言环境?

转载 作者:行者123 更新时间:2023-12-04 13:04:52 25 4
gpt4 key购买 nike

以下示例似乎显示了 Qt 中的一个错误。还是我弄错了?

std::cout << atof("0.456") << std::endl; // OK prints 0.456
QApplication app (argc, argv);
//QLocale::setDefault(QLocale::C); // No effect at all.
std::cout << atof("0.456") << std::endl; // do not work on on fr_FR.UTF-8, print 0.

当使用非标准语言环境时,在我的示例 fr_FR.UTF-8 中,创建 QApplication 似乎会更改系统语言环境,因为 atof 使用它来进行转换。

在我看来,创建 QApplication 会提取系统语言环境并使用它调用 setenv。

最佳答案

来自 Qt 文档

Locale Settings

On Unix/Linux Qt is configured to use the system locale settings by default. This can cause a conflict when using POSIX functions, for instance, when converting between data types such as floats and strings, since the notation may differ between locales. To get around this problem, call the POSIX function setlocale(LC_NUMERIC,"C") right after initializing QApplication or QCoreApplication to reset the locale that is used for number formatting to "C"-locale.

关于qt - Qt 是否强制系统语言环境?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34877942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com