<分区>
我在 visualc++ 2010 中尝试该示例代码但它崩溃了
QString fileName = "helloworld";
std::string str = fileName.toStdString();
标签 c++ qt visual-c++ qstring
<分区>
我在 visualc++ 2010 中尝试该示例代码但它崩溃了
QString fileName = "helloworld";
std::string str = fileName.toStdString();
最佳答案
How to convert 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.
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();
关于c++ - QString 到 std::string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11191762/