Convert std::string to QString

Fred Foo picture Fred Foo · Dec 2, 2010 · Viewed 79.7k times · Source

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?

Answer

Jackpap picture Jackpap · Sep 1, 2013

QString::fromStdString(content) is better since it is more robust. Also note, that if std::string is encoded in UTF-8, then it should give exactly the same result as QString::fromUtf8(content.data(), int(content.size())).