转载自
https://blog.csdn.net/mihang2/article/details/39026865
QString中包含中文的时候, 转为char *
void FileEncWidget::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 *)malloc(len + 1);WideCharToMultiByte(CP_ACP, NULL, wIn.c_str(), wcslen(wIn.c_str()), *pOut, len, NULL, NULL);(*pOut)[len] = '\0';
}
当然也有这种方法:
https://blog.csdn.net/shihoongbo/article/details/83374257