What functional pair in QString to use to convert to / from std :: string?

I am working on a project that we want to use in Unicode, and may be in countries such as Japan, etc. We want to use std :: string for a base type that contains string data in the data layer (see Qt, MSVC and / Zc: wchar_t- == I want to blow up the world , why). The problem is that I'm not quite sure which pair of functions (to / from) is used for this and to be sure that we are 100% compatible with what the user can enter in the Qt layer.

A look at / fromStdString indicates that I will have to use setCodecForCStrings. The documentation for this function, however, indicates that I do not want to do this for things like Japanese. This is the kit I would like to use. Does anyone know enough to explain how I set it up, if possible?

Another option that looks like I'm sure it works with to / fromUTF8 functions. This will require a two-step approach, although I would prefer a different one, if possible.

Is there something I missed?

+3
source share
1 answer

( QString). QTextCodec, , . QByteArray std::string. , QByteArray std::string. QString, , toStdString :

inline std::string QString::toStdString() const
{ const QByteArray asc = toAscii(); return std::string(asc.constData(), asc.length()); }

toAscii , QTextCodec::setCodecForCString.

, , , . .

. UTF-8, toStdString UTF-8. .:)

+2

Source: https://habr.com/ru/post/1783263/


All Articles