How to convert LPTSTR to QString

Hi, can someone help me convert LPTSTR to QString

+4
source share
5 answers

In docs, you will see that Qstring provides a static function to convert from ascii and Unicode strings:

  • QString fromAscii (const char * ascii, int len ​​= -1)
  • QString fromLatin1 (const char * chars, int len ​​= -1)
  • QString fromUtf8 (const char * utf8, int len ​​= -1)
  • QString fromLocal8Bit (const char * local8Bit, int len ​​= -1)
  • QString fromUcs2 (const unsigned short * str)

Check if you are using ascii or unicode and choose your poison.

+7
source

QString :: fromWCharArray is what worked for me.

+6
source

To convert a QString to LPTSTR or LPCTSTR:

QString src; LPTSTR dest=(LPTSTR)src.utf16(); 

to convert from LPTSTR or LPCTSTR to QString:

 src=QString::fromUtf16(dest); 
+4
source

Use QString :: fromUcs2 to convert strings.

0
source

It is good quality

QString str ("ddddd"); LPCTSTR lstr = (LPCTSTR) str.data ();

0
source

Source: https://habr.com/ru/post/1307756/


All Articles