string与QString转换(string既可以是utf8,也可以是gbk)
AtUtf8.h
- #ifndef _QT_UTF8_H
- #define _QT_UTF8_H
- #include <QString>
- #include <string>
- using std::string;
- class AfUtf8
- {
- public:
- // QString(Unicode) -> std::string (UTF8)
- static string ToString(const QString& qstr)
- {
- QByteArray arr = qstr.toUtf8();
- string cstr = arr.data();
- return cstr;
- }
- // std::string (UTF8) -> QString(Unicode)
- static QString ToQString(const string& cstr)
- {
- QString qstr = QString::fromUtf8(cstr.c_str(), cstr.length());
- return qstr;
- }
- };
- #endif
AtGbk.h
- #ifndef _QT_GBK_H
- #define _QT_GBK_H
- #include <QString>
- #include <QTextCodec>
- #include <string>
- using std::string;
- class AfGbk
- {
- public:
- // QString(Unicode) -> std::string (GBK)
- static string ToString(const QString& qstr)
- {
- QTextCodec* pCodec = QTextCodec::codecForName("gb2312");
- if(!pCodec) return "";
- QByteArray arr = pCodec->fromUnicode(qstr);
- string cstr = arr.data();
- return cstr;
- }
- // std::string (GBK) -> QString(Unicode)
- static QString ToQString(const string& cstr)
- {
- QTextCodec* pCodec = QTextCodec::codecForName("gb2312");
- if(!pCodec) return "";
- QString qstr = pCodec->toUnicode(cstr.c_str(), cstr.length());
- return qstr;
- }
- };
- #endif
http://blog.csdn.net/bladeandmaster88/article/details/53469959
string与QString转换(string既可以是utf8,也可以是gbk)的更多相关文章
- QString 与 string转换
[1]QString 转换为string QString qString("好好学习天天向上"); std::string stdString = qString.toStdStr ...
- QString与string的相互转换
1.QString转换String string s = qstr.toStdString(); 2.String转换QString QString qstr2 = QString::fromStdS ...
- QString与string的相互转换【转载】
文章转载自https://blog.csdn.net/qq_33485434/article/details/80680506 1.QString转换String string s = qstr.to ...
- JAVA中List转换String,String转换List,Map转换String,String转换Map之间的转换类
<pre name="code" class="java"></pre><pre name="code" cl ...
- android 中List转换String,String转换List 改进版本
原来博客地址http://blog.csdn.net/qq7342272/article/details/6830907 使用原作者贴的代码不是很好用,不能正常运行,所以我稍微改进了一下,特来分享给大 ...
- C#中char[]与string之间的转换;byte[]与string之间的转化
目录 1.char[]与string之间的转换 2.byte[]与string之间的转化 1.char[]与string之间的转换 //string 转换成 Char[] string str=&qu ...
- string与QString之间的转换(两种方法:fromStdString直接转换,或者fromLocal8Bit(cstr.c_str())
string str;QString qstr; //从QString 到 std::stringstr = qstr.toStdString(); //从std::string 到QStringqs ...
- Qt QString与string的转换
QString --> string QString.toStdString(); string --> QString QString::fromStdString(string);
- QString, Std::string, char *相互转换
Qt 库中对字符串类型进行了封装,QString 类提供了所有字符串操作方法,给开发带来了便利. 由于第三方库的类型基本上都是标准的类型,即使用std::string或char *来表示字符 (串) ...
随机推荐
- 【71.76%】【codeforces 732A】Buy a Shovel
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Function函数
一般大家都用这个写法来定义一个函数: function Name([parameters]){ functionBody }; //alert(typeof Name) // Function 当我们 ...
- WPF 使用 Edge 浏览器
原文:WPF 使用 Edge 浏览器 版权声明:博客已迁移到 http://lindexi.gitee.io 欢迎访问.如果当前博客图片看不到,请到 http://lindexi.gitee.io 访 ...
- Linux开关命令(shutdown,reboot,halt,init)
命令简短 shutdown,poweroff,reboot,halt,init都能够进行关机,大致使用方法. /sbin/halt [-n] [-w] [-d] [-f] [-i] [-p] ...
- exponential family distribution(指数族分布)
1. exponential family 给定参数 η,关于 x 的指数族分布定义为如下的形式: p(x∣∣η)=h(x)g(η)exp{ηTu(x)} 其中 x 可以为标量也可以为矢量,可以为离散 ...
- 解决关于archlinux升级至3.16.1,Xorg桌面环境无法进入的问题
[现象]有终端输入username,password后,桌面环境启动失败. [报错]log文件里显示: (EE) Fatal server error: (EE) xf86OpenConsole: V ...
- 对XAML进行编辑的辅助类(XamlHelper)
原文:对XAML进行编辑的辅助类(XamlHelper) // XamlHelper.cs// --------------------------------------------// 对XAML ...
- #747 –在WPF程序的触摸操作中使用惯性移动 (Implementing Inertia during Touch Manipulation)
原文:#747 –在WPF程序的触摸操作中使用惯性移动 (Implementing Inertia during Touch Manipulation) 原文地址:https://wpf.2000th ...
- WPF 呼吸灯特效
原文:WPF 呼吸灯特效 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u014117094/article/details/46738621 pa ...
- cross-compile-openssl-windows.sh,cross-compile-curl-windows.sh,cross-compile-zlib-windows.sh,build-zlib-visual-studio-2015-cli.bat
https://gist.github.com/artynet build zlib with Visual Studio CLI toolhttps://gist.github.com/artyne ...