#include <qtextcodec.h>
#include
构造函数
{
ui.setupUi(this);
std::string temp("模板方法");
char str[10] = {0};
setWindowTitle(TemplateMethod::Gb2312_utf8(temp, str));
}
char * TemplateMethod::Gb2312_utf8(std::string strutf8, char* str)
{
//头文件QTextCodec
QTextCodec* utf8Codec = QTextCodec::codecForName(“utf-8”);
QTextCodec* gb2312Codec = QTextCodec::codecForName(“gb2312”);
QString strUnicode = gb2312Codec->toUnicode(strutf8.c_str());
QByteArray ByteUtf8 = utf8Codec->fromUnicode(strUnicode);
strcpy(str, ByteUtf8.data());
return str;
}
char* TemplateMethod::utf8_Gb2312(std::string strgb2312, char* str)
{
QTextCodec* utf8Codec = QTextCodec::codecForName(“utf-8”);
QTextCodec* gb2312Codec = QTextCodec::codecForName(“gb2312”);
QString strUnicode = utf8Codec->toUnicode(strgb2312.c_str());
QByteArray ByteGb2312 = gb2312Codec->fromUnicode(strUnicode);
strcpy(str, strgb2312.data());
return str;
}