QString 和 std::string 转换

来源:互联网 发布:python curses 编辑:程序博客网 时间:2024/06/12 01:29

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 anywherestd::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());

原创粉丝点击