QString中包含中文的時候, 轉爲char *

轉載自
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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章