Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15.6, 6.0.1, 6.1.3, 6.2.0
-
None
Description
Qt already has functions to convert from and to std::u16string / std::u32string.
Since c++20 and c23, we have char8_t. It would be good, to also have functions which convert from/to std::u8string.
QString::toStdU8String is missing and should look like this for pre c++20:
inline std::string QString::toStdU8String () const { return toUtf8().toStdString(); }
for c++20:
QString::toStdU8String is missing and should look like this:
inline std::string QString::toStdU8String () const { return toUtf8().toStdU8String(); }
Optional:
I also noticed that the `QString::toStdString` function is ambiguous: C++ does not specify an encoding for it, but it is only used together with the locale encoding. This makes the function unusable in cases where the `std::locale` is not based on UTF-8. This is particularly fatal in China, where UTF-8 is practically forbidden as the default on desktops (even on UNIX Systems). But also on Windows computers world wide, which typically do not use utf-8 as default, instead ANSI is used.
After the discussion below, I won't propose anymore to deprecate it, but rather to also add `QString::from/toLocalStdString`.