QT meeGo 中文字符串排序
来源:互联网 发布:golang 1.7 编辑:程序博客网 时间:2024/05/21 10:20
Qt类中的qSort()函数提供了对字符串的排序功能。要利用qSort为中文进行排序则需要我们提供一个针对中文比较规则的比较器。 Meego Touch Framework 中的MCollator实现了该功能。更准确地说是MCollator实现了所有国家语言的排序功能。 简单的用法如下。 MLocale loc; // 这里设置对应国家的语言和排序方法 QStringList stringList; 中文有按照拼音(pinyin)和笔画(stroke)两种排序方式. 所以我们构造MLocale的时候可以用 //根据拼音或笔画选择一种 完整的代码如下 #include <QCoreApplication> int main(int argc,char *argv[]){ QTextCodec *tc=QTextCodec::codecForName(“utf8″); qSort(stringList.begin(), stringList.end(), mcomp); 如果是按拼音排序输出将是 (“策”, “党”, “的”, “克”, “西”, “亚”, “政”). 需要注意的是编译该代码需要在你的工程文件.pro中加入CONFIG+=meegotouch.
MCollator comp = loc.collator();
//add contents to stringList
qSort(stringList.begin(), stringList.end(), comp); // sorts the list
MLocale loc(“zh_CN@collation=pinyin”);
MLocale loc(“zh_CN@collation=stroke”);
#include <QObject>
#include <MLocale>
#include <MCollator>
#include <QStringList>
#include <QDebug>
#include <QTextCodec>
QCoreApplication app(argc,argv);
//MLocale loc(locale_name);
MLocale loc(“zh_CN@collation=pinyin”);
MCollator mcomp = loc.collator();
QTextCodec::setCodecForCStrings(tc);
QStringList stringList;
//stringList << “bb” << “da” << “aa” << “ab”;
stringList<<”党”<<”的”<<”政”<<”策”<<”亚”<<”克”<<”西”;
qDebug()<<stringList;
}
而按笔画排序输出将是 (“西”, “克”,”的”,”政”, “党”, “策”, “亚”).
- QT meeGo 中文字符串排序
- QT 中文字符串排序
- qt 中文排序
- 【QT】字符串中文
- 中文字符串排序解决方案
- Meego:阿汤学QT--PyQT
- QT&Meego Touch
- Meego:为什么是QT?
- Meego:阿汤学QT-- QT Designer
- QT中文字符串个数问题
- qt & qt creator 中文字符串查找问题
- Java字符串排序中文+数字
- java中的中文字符串排序
- Meego:为什么是QT(转载)
- Meego:阿汤学QT--PyQT modules
- Meego:阿汤学QT--QWidget modules
- Meego with Qt初体验
- Meego下搭建QT环境
- android busybox 配置
- [转]javascript面向对象之我解
- 高级编程能力
- 研发团队问卷调查
- V8和JavaScriptCore在Android Froyo上的速度比较
- QT meeGo 中文字符串排序
- vb做的贪吃蛇
- how to dubug malloc_error_break
- [export excel]Oracle Form導入sql查詢再導出CSV查詢結果( Using EXEC_SQL Package)
- [易飞]新增工作中心
- How to debug EXC_BAD_ACCESS
- 笔试中遇到的一些算法问题
- 数组名和指针详解
- 跨域资源共享的10种方式