Andrew
Andrew

Reputation: 24846

how to convert std::string to QString

I have a problem:

std::string str("character/test/raw");
qDebug() << QString::fromStdString(str);

and the output is:

"]AIIIIIIIIIIIIIIIIIIIIIIIIIIIII"

I think the problem is in encoding but don't know how to fix it. Please help

Upvotes: 8

Views: 9565

Answers (2)

Alessandro Pezzato
Alessandro Pezzato

Reputation: 8802

string to const char*, then to qstring

std::string str("character/test/raw");
QString qstr(str.c_str());
qDebug() << qstr;

Upvotes: 9

BЈовић
BЈовић

Reputation: 64203

Is your QT compiled with STL compatible enabled option?

Maybe you can use fromUtf8 or one of other static functions of QString.

Upvotes: 6

Related Questions