c++ - QString 到 std::string

标签 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/

相关文章:

c# - 如何确保可以加载 auth.dll?

c++ - 为什么在释放由 apriltags image_u8_create() 分配并存储在 C++ 指针的 2D vector 中的内存时出现错误?

qt - 动画 `positionViewAtIndex`

python - 为实时数据绘图实现 pyqtgraph

c++ - 重载函数成员 C++ 的问题

在 ReadFile() 之上创建异步 "ReadFileMany()"

c++ - 使用winsock vc++通过UDP发送数字数组

c++ - 替换 C++ 基类方法?

c++ - 为什么取消引用迭代器会切断输出流?

c++ - 没有opengl的QT项目