Qt错误:'const class QString'没有名为'toStdString'的成员

时间:2013-04-04 08:45:53

标签: c++ qt compiler-errors

我收到此错误error: 'const class QString' has no member named 'toStdString'虽然QString有错误。 (link)

代码

    std::string Message::toStdString() const 
    {
        return m_string.toStdString();
    }

1 个答案:

答案 0 :(得分:2)

直接从这里复制答案:

How to convert QString to std::string?

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