Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I am using a dll, which takes a TCHAR and TCHAR*parameter in its functions.
and my GUI elements from QT are in the form of QString.

I have been working since hours to figure out a way to convert a QString value to TCHAR / TCHAR*
have tried many forms and types..still no joy.
please can i get a code example to convert a QString value to TCHAR / TCHAR*

QString Value to TCHAR tValue
and QString Value to TCHAR* rValue

OR is any code help for converting a char* value to TCHAR and TCHAR*


Thanks a lot.
Posted
Comments
Jochen Arndt 29-May-13 9:19am    
The answer depends on the Unicode setting of your project. If your project is Unicode, TCHAR is defined as WCHAR and with non-Unicode builds, TCHAR is defined as char.

Because QString uses 16-bit Unicode internally, you can use the constData() and unicode() member functions and cast the const QChar* return value to const TCHAR* and the at() function or [] operator casting to TCHAR with Unicode builds.

With non-Unicode builds, you must convert the characters/strings using one of the conversion functions like toAscii(), toLatin1, toLocal8Bit() and cast the returned QByteArray to char*.

 
Share this answer
 
Quote:
QString myString to TCHAR wString ??

QString has the toWCharArray[^] method.
 
Share this answer
 
Hello Jochen,
QT uses UTF-8 encoding.
And i have googled..issue is not from QString to char*
but
QString to TCHAR which is a (WCHAR in unicode)

can i get some code help??

QString myString to TCHAR wString ??
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900