[Development] Qt6: Adding UTF-8 storage support to QString
Thiago Macieira
thiago.macieira at intel.com
Fri Jan 18 17:21:38 CET 2019
On Friday, 18 January 2019 08:13:40 PST Kai Koehne wrote:
> 1. We generally compile Qt code with QT_NO_CAST_FROM_ASCII that disables the
> QString(const char *) overload. And we do that so that you have to make it
> explicit whether you really want to do the implicit conversion from UTF-8
> to UTF-16, use QStringLiteral() to encode it as UTF-16 at compile time, or
> rather have it translated with a tr() call.
>
> I think for Qt code explicit is better than implicit, so I actually would
> stay with QT_NO_CAST_FROM_ASCII.
Actually, what we should do is allow everywhere
functionTakingString(u"Tor Arne Vestbø")
// (note the u)
Which causes the compiler to encode the string in UTF-16, bypassing the need
for runtime decoding, and enforcing sources as UTF-8, so we get consistent
binaries. It's just one step short of QStringLiteral in that it will still
allocate memory, but it only needs a memcpy. Such code also works with
functions taking QStringView without memory allocation.
We all know that QStringLiteral has drawbacks when it comes to unloading
modules. For QtCore, obviously QStringLiteral is not a problem, but other
modules may decide to avoid it.
PS: I still want to improve QStringLiteral, but it will still be different
from a pure char16_t literal.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Development
mailing list