TCHAR 转 QString wchar_t * 转QString

#ifdef UNICODE

#define QStringToTCHAR(x)     (wchar_t*) x.utf16()

#define PQStringToTCHAR(x)    (wchar_t*) x->utf16()

#define TCHARToQString(x)     QString::fromUtf16((x))

#define TCHARToQStringN(x,y)  QString::fromUtf16((x),(y))

#else

#define QStringToTCHAR(x)     x.local8Bit().constData()

#define PQStringToTCHAR(x)    x->local8Bit().constData()

#define TCHARToQString(x)     QString::fromLocal8Bit((x))

#define TCHARToQStringN(x,y)  QString::fromLocal8Bit((x),(y))

#endif

  

wchar_t* 转QString

wchar_t* wptr = L"test";
QString ret = QString::fromWCharArray(wptr);
QString ret2 = QString((QChar*)wptr, wcslen(wptr));

QString 转wchar_t*
wchar_t szBuf[1024];
QString str = tr("hello");
wcscpy_s(reinterpret_cast<wchar_t*>(szBuf),
    sizeof(szBuf) / sizeof(wchar_t),
    reinterpret_cast<const wchar_t*>(str.utf16()));

  

posted on 2013-07-19 14:43  涛涛宝贝  阅读(7615)  评论(0编辑  收藏  举报

导航