Created
November 1, 2017 08:42
-
-
Save 0xlitf/f0dec74bab67a5deb3b22f4369bb1861 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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