[Development] Why can't QString use UTF-8 internally?

Olivier Goffart olivier at woboq.com
Wed Feb 11 01:38:12 CET 2015


On Tuesday 10 February 2015 15:33:12 Thiago Macieira wrote:
> On Tuesday 10 February 2015 23:17:21 Allan Sandfeld Jensen wrote:
> > Maybe with C++11 we don't need QString that much anymore. Use std::string
> > with UTF8 and std::u32string for UCS4.
> > 
> > For Qt6 it would be worth considering how many of our classes still makes
> > sense. Those we want CoW semantics on would make sense, but if we don't
> > really want that on strings, maybe every framework having its own string
> > class is finally obsolete in C++?
> 
> Eh... have you tried to convert a UTF-8 or UTF-16 or UCS-4 string to the
> locale's narrow character set without using QString?

with std::ctype::tonarrow?

> Have you tried to convert a number to string? You need C++14 to do that
> reasonably, since std::to_string didn't exist in C++11. 

std::to_string is part of C++11.

> How about the reverse? The only way to do that is sscanf or
> std::istringstream.

std::stoi

> Have you tried to uppercase or lowercase a string using only the Standard
> Library?

std::ctype::toupper


And if you think they are not pretty because they are not using camel case, we 
can still have in Qt functions like qToUpper and qToLower or QTextCodec

> We may want to have this discussion for QVector vs std::vector. For QString 
> and QByteArray, there's no discussion: they stay, period.

I understand that we are used to the convenience of the API of QString, but it 
is still a question of taste at this point. And not using the standard library 
type is a problem when it comes to integrate with others.
If we break source compatibility and ABI consideration to accept std::vector, 
then why not std::string and related?

-- 
Olivier 

Woboq - Qt services and support - http://woboq.com - http://code.woboq.org




More information about the Development mailing list