0

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.

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
0xAX
  • 20,957
  • 26
  • 117
  • 206

2 Answers2

3

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.

MacGucky
  • 2,494
  • 17
  • 17
0

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.

Nemanja Trifunovic
  • 24,346
  • 3
  • 50
  • 88