Skip to content

Instantly share code, notes, and snippets.

@0xlitf
Created November 1, 2017 08:42
Show Gist options
  • Save 0xlitf/f0dec74bab67a5deb3b22f4369bb1861 to your computer and use it in GitHub Desktop.
Save 0xlitf/f0dec74bab67a5deb3b22f4369bb1861 to your computer and use it in GitHub Desktop.
#include <QTextCodec>
inline QString GBK2UTF8(const QString &inStr)
{
QTextCodec *gbk = QTextCodec::codecForName("GB18030");
QTextCodec *utf8 = QTextCodec::codecForName("UTF-8");
QString g2u = gbk->toUnicode(gbk->fromUnicode(inStr)); // gbk convert utf8
return g2u;
}
inline QString UTF82GBK(const QString &inStr)
{
QTextCodec *gbk = QTextCodec::codecForName("GB18030");
QTextCodec *utf8 = QTextCodec::codecForName("UTF-8");
QString utf2gbk = gbk->toUnicode(inStr.toLocal8Bit());
return utf2gbk;
}
inline std::string gbk2utf8(const QString &inStr)
{
return GBK2UTF8(inStr).toStdString();
}
inline QString utf82gbk(const std::string &inStr)
{
QString str = QString::fromStdString(inStr);
return UTF82GBK(str);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment