c++stringqtutf-8qstring

Convert std::string to QString


I've got an std::string content that I know contains UTF-8 data. I want to convert it to a QString. How do I do that, avoiding the from-ASCII conversion in Qt?


Solution

  • There's a QString function called fromUtf8 that takes a const char*:

    QString str = QString::fromUtf8(content.c_str());