【问题标题】:How to convert unicode QString to an std::string?如何将 unicode QString 转换为 std::string?
【发布时间】:2011-07-21 07:24:40
【问题描述】:

我需要将QString 转换为std::string。但是,如果这个字符串包含 unicode 符号,我会得到????。如何使用正确的编码转换字符串?

谢谢。

【问题讨论】:

    标签: c++ unicode character-encoding std qstring


    【解决方案1】:

    到目前为止,您是如何尝试转换字符串的?

    根据documentation std::string QString::toStdString () 应该将unicode-data 转换为ascii-string

    但请注意,您会丢失 ascii 无法处理的特殊字符。

    【讨论】:

      【解决方案2】:

      根据 Qt 文档,QString::toStdString 内部使用 toAscii() 函数:http://doc.qt.nokia.com/latest/qstring.html#toStdString

      基本上,您需要创建自己的转换器函数,以使用 QString::toUtf8() 代替。

      【讨论】:

        猜你喜欢
        • 2011-05-11
        • 2013-08-21
        • 2011-05-19
        • 2013-05-11
        • 2014-09-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-23
        相关资源
        最近更新 更多