QString to std::string
One of the things you should remember when converting QString to std::string is the fact that QString is UTF-16 encoded while std::string... May have any encodings.
So the best would be either:
QString qs;
// Either this if you use UTF-8 anywhere
std::string utf8_text = qs.toUtf8().constData();
// or this if you on Windows :-)
std::string current_locale_text = qs.toLocal8Bit().constData();
The suggested (accepted) method may work if you specify codec.
std::string to QString
There's a QString function called fromUtf8 that takes a const char*:
QString str = QString::fromUtf8(content.c_str());
本文介绍了如何在C++中将QString转换为std::string,以及反之亦然的方法。QString通常使用UTF-16编码,而std::string可以采用多种编码方式。文中提供了具体的代码示例,展示了使用toUtf8()和toLocal8Bit()进行转换的过程。

3271

被折叠的 条评论
为什么被折叠?



