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()));

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM