Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ QT QT-Creator
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 29-May-13 2:15am
Comments
Jochen Arndt at 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*.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Quote:
QString myString to TCHAR wString ??

QString has the toWCharArray[^] method.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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 ??
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 30 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100