wchar_t *QString2Wchar(QString buf)
{
return (wchar_t*)reinterpret_cast<const wchar_t *>(buf.utf16());
}
QString Wchar2QString(wchar_t *buf)
{
return QString::fromWCharArray(buf);
}
demo:
wchar_t path[1024]={0};
GetModuleFileName(NULL, path, 1024);
qDebug()<<Wchar2QString(path);
wchar_t *path2;
path2=QString2Wchar("hello xiaohai");
wcout<<path2<<endl;
result:
"D:\\Projects\\QtProjects\\build-Demo-Desktop_Qt_5_12_12_MinGW_32_bit-Debug\\debug\\Demo.exe"
hello xiaohai