5

I am getting this error error: 'const class QString' has no member named 'toStdString' though QString has it. (link).

The code

    std::string Message::toStdString() const 
    {
        return m_string.toStdString();
    }
1
  • 4
    "This operator is only available if Qt is configured with STL compatibility enabled."
    – Erik
    Apr 4, 2013 at 8:48

1 Answer 1

3

Answer directly copied from here:

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();
2
  • This happens when Qt was not compiled with STL support. May 4, 2020 at 13:15
  • what an elegant, intuitive design! Jan 4, 2022 at 10:02

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.