QTextCodec

       

QString类提供了一个Unicode文本和经典的C以零结尾的字符数组的抽象。 

       QString使用隐含共享,这使它非常有效率并且很容易使用。 
所有的QString的方法都使用const char *参数,const char *被解释为经典的C风格的以零结尾的ASCII字符串。所以const char *参数为0是合法的。如果const char *不是以零结尾的,结果是不确定的。把经典的C字符串复制到QString的函数将不会复制结尾的0字符。QString的QChar数组(可以通过 unicode()返回)通常不以零结尾。如果你需要把 QString传递到一个需要C的以零结尾的字符串,请使用latin1()。 
        没有分配任何东西的QString是零,也就是长度和数据指针都为0。引用空字符串(“”,一个单一的'\0'字符)的QString是空。零和空这两个 QString在方法中都是合法的。把(const char *) 0赋值给QString给定了一个零QString。为了方便,QString::null是一个零QString。当排序的时候,空字符串在最前面,然 后是非空字符串,然后才是零字符串。我们建议使用if ( !str.isNull() ),而不是if ( !str )来检测非零字符串,关于解释说明也可以参考operator!()。 
        注意如果你发现你正在混合使用QCString、QString和QByteArray,这将会导致很多不必要的复制并且也许会预示着你正在处理的真实自 然数据是不确定的。如果数据是以零结尾的八位数据,请使用QCString;如果它是没有结尾的(也就是包含0)八位数据,请使用QByteArray; 如果它是文本,请使用QString。 
        字符串列表可以使用QStringList类来处理。你可以使用QStringList::split()来把一个字符串分割为一个字符串列表,并且可以 使用QStringList::join()把一个字符串列表连接成一个使用随意间隔符的字符串。你也可以使用QStringList::grep()从 一个字符串列表中获得包含特定子字符串或者包含匹配特定的regex的字符串列表。 

QTextCodec * QTextCodec::codecForName ( const char * name ) [static]    //"GBK"
Searches all installed QTextCodec objects and returns the one which best matches name; the match is case-insensitive(不区分大小写). 
Returns 0 if no codec matching the name name could be found.
(codecForName函数是根据参数中的编码名称,在系统已经安装的编码方案中需找最佳的匹配编码类型,该查找是大小写不敏感的。如果没有找到,就返回0)

void QTextCodec::setCodecForTr ( QTextCodec * c ) [static]
Sets the codec used by QObject::tr() on its argument to c. If c is 0 (the default), tr() assumes Latin-1.

void QTextCodec::setCodecForCStrings ( QTextCodec * codec ) [static]
Sets the codec used by QString to convert to and from const char * and QByteArrays. If the codec is 0 (the default), QString assumes Latin-1.

void QTextCodec::setCodecForLocale ( QTextCodec * c ) [static]

Set the codec to c; this will be returned by codecForLocale(). If c is a null pointer, the codec is reset to the default.

QTextCodec *codec = QTextCodec::codecForName("GBK");
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);    





  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值