[Qt-interest] QString to TCHAR* and back
Nuno Correia
npaulo.nuno at gmail.com
Wed Feb 24 18:36:32 CET 2010
Hi,
Try this code, it's work fine for my problem.
*QString to TCHAR*
TCHAR buffer[ MAX_PATH ];
filepath.toWCharArray( buffer );
buffer[ filepath.length() ] = '\0';
*TCHAR to QString*
TCHAR* szMessage = _T("Hello, World");
#ifdef UNICODE
qstrMessage = QString::fromUtf16((ushort*)szMessage);
#else
qstrMessage = QString::fromLocal8Bit(szMessage);
#endif
On 24 February 2010 16:26, Dan White <ygor at comcast.net> wrote:
> How about QString::fromStdWString and QString::fromWCharArray and
> QString::toStdWString and QString::toWCharArray ?
>
> Search for "wchar" on the QString documentation page.
>
> “Sometimes I think the surest sign that intelligent life exists elsewhere
> in the universe is that none of it has tried to contact us.”
> Bill Waterson (Calvin & Hobbes)
>
> ----- Duane Hebert <spoo at flarn.com> wrote:
> > What is the recommend way to do these conversions?
> >
> > If found this on the net and it seems to work:
> > #ifdef UNICODE
> > #define QStringToTCHAR(x) (wchar_t*) x.utf16()
> > #define TCHARToQString(x) QString::fromUtf16((x))
> > #else
> > #define QStringToTCHAR(x) x.local8Bit().constData()
> > #define TCHARToQString(x) QString::fromLocal8Bit((x))
> > #endif
> >
> > I'm using Qt 4.5.1 win commercial.
> >
> >
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100224/ef53034c/attachment.html
More information about the Qt-interest-old
mailing list