天天看點

包含中文的QString 轉 char*

void QString2ANSI(QString text, char **pOut)
{
    std::wstring wIn = text.toStdWString();
    char *pcstr = (char *)malloc(sizeof(char)*(2 * wcslen(wIn.c_str())+1));
    memset(pcstr , 0 , 2 * wcslen(wIn.c_str())+1 );
    int len = WideCharToMultiByte(CP_ACP, NULL, wIn.c_str(), wcslen(wIn.c_str()), NULL, 0, NULL, NULL);
    *pOut = (char *)oef_crt_malloc(len + 1);
    WideCharToMultiByte(CP_ACP, NULL, wIn.c_str(), wcslen(wIn.c_str()), *pOut, len, NULL, NULL);
    (*pOut)[len] = '\0';
}
           

繼續閱讀