kajojeq
kajojeq

Reputation: 904

Convert TCHAR* to QString

How to convert easiest way in Qt?

int recordSize = 1000;
TCHAR* qRecord = new TCHAR[recordSize];
//here I get data form other function
//here I try to display
qString() << QString::fromWCharArray(qRecord,recordSize);//gives many ????
printf("%s",qRecord); // this work perfectly

I tried with wcstombs, formStdWString nad other but nothing seems to work. Thanks for any help

Upvotes: 5

Views: 8036

Answers (2)

Rashid Mansouri
Rashid Mansouri

Reputation: 131

@kajojeq no, your second answer is not correct. because when the encoding is set to utf16(or even utf8 sometimes) the s variable only save one character. correct conversion is:

QString str = QString::fromWCharArray(qrecord)

Upvotes: 7

kajojeq
kajojeq

Reputation: 904

 QString s= (LPSTR)qRecord;

worked. thanks

Upvotes: 4

Related Questions