0xAX
0xAX

Reputation: 21837

How to convert unicode QString to an std::string?

I need convert a QString to an std::string. However, if this string contains unicode symbols, I get ????. How can I convert the string with the proper encoding?

Thank you.

Upvotes: 0

Views: 1324

Answers (2)

Nemanja Trifunovic
Nemanja Trifunovic

Reputation: 24557

According to Qt documentation, QString::toStdString internally uses toAscii() function: http://doc.qt.nokia.com/latest/qstring.html#toStdString

Basically, you'll need to make your own converter function that would use QString::toUtf8() instead.

Upvotes: 0

MacGucky
MacGucky

Reputation: 2504

How did you try to convert the string so far?

According to documentation std::string QString::toStdString () should convert the unicode-data to an ascii-string

But be warned that you loose special-chars which ascii can't handle.

Upvotes: 3

Related Questions