15

Convert WCHAR to QString in Qt. Please help me to implement it to complete this convertion.

Harry Fox
  • 603
  • 2
  • 6
  • 11

1 Answers1

31

There are to/from WCharArray methods that are static members of QString:

http://doc.qt.io/qt-4.8/qstring.html#fromWCharArray

http://doc.qt.io/qt-4.8/qstring.html#toWCharArray

demonplus
  • 5,613
  • 12
  • 49
  • 68
  • It looks like these links are broken – Shafik Yaghmour Mar 22 '13 at 20:36
  • 1
    @ShafikYaghmour Thanks for the heads-up. Fixed 'em. But I sure wish these guys would have read Tim's [Cool URIs don't change](http://www.w3.org/Provider/Style/URI.html). :-/ – HostileFork says dont trust SE Mar 31 '13 at 16:21
  • You might want to consider editing to include an example as well. – Shafik Yaghmour Mar 31 '13 at 16:43
  • `QString::fromUtf16()` also works. I was getting linking errors in QT 5 on using `QString::fromWCharArray()`. see https://forum.qt.io/post/165335. Linking error I was getting - `unresolved external symbol "__declspec(dllimport) public: static class QString __cdecl QString::fromWCharArray(unsigned short const *,int)" (__imp_?fromWCharArray@QString@@SA?AV1@PBGH@Z)` – Sahil Singh Dec 07 '20 at 18:41