转载地址: https://www.cnblogs.com/fuyanwen/p/3200536.html #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())); |