📄 qtextcodec.3qt
字号:
'\" t.TH QTextCodec 3qt "9 December 2002" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQTextCodec \- Conversion between text encodings.SH SYNOPSISAlmost all the functions in this class are reentrant when Qt is built with thread support. The exceptions are \fB~QTextCodec\fR(), \fBsetCodecForTr\fR(), \fBsetCodecForCStrings\fR(), and \fBQTextCodec\fR().</p>.PP\fC#include <qtextcodec.h>\fR.PPInherited by QBig5Codec, QBig5hkscsCodec, QEucJpCodec, QEucKrCodec, QGb18030Codec, QJisCodec, QHebrewCodec, QSjisCodec, and QTsciiCodec..PP.SS "Public Members".in +1c.ti -1c.BI "virtual \fB~QTextCodec\fR ()".br.ti -1c.BI "virtual const char * \fBname\fR () const = 0".br.ti -1c.BI "virtual const char * \fBmimeName\fR () const".br.ti -1c.BI "virtual int \fBmibEnum\fR () const = 0".br.ti -1c.BI "virtual QTextDecoder * \fBmakeDecoder\fR () const".br.ti -1c.BI "virtual QTextEncoder * \fBmakeEncoder\fR () const".br.ti -1c.BI "virtual QString \fBtoUnicode\fR ( const char * chars, int len ) const".br.ti -1c.BI "virtual QCString \fBfromUnicode\fR ( const QString & uc, int & lenInOut ) const".br.ti -1c.BI "QCString \fBfromUnicode\fR ( const QString & uc ) const".br.ti -1c.BI "QString \fBtoUnicode\fR ( const QByteArray & a, int len ) const".br.ti -1c.BI "QString \fBtoUnicode\fR ( const QByteArray & a ) const".br.ti -1c.BI "QString \fBtoUnicode\fR ( const QCString & a, int len ) const".br.ti -1c.BI "QString \fBtoUnicode\fR ( const QCString & a ) const".br.ti -1c.BI "QString \fBtoUnicode\fR ( const char * chars ) const".br.ti -1c.BI "virtual bool \fBcanEncode\fR ( QChar ch ) const".br.ti -1c.BI "virtual bool \fBcanEncode\fR ( const QString & s ) const".br.ti -1c.BI "virtual int \fBheuristicContentMatch\fR ( const char * chars, int len ) const = 0".br.ti -1c.BI "virtual int \fBheuristicNameMatch\fR ( const char * hint ) const".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "QTextCodec * \fBloadCharmap\fR ( QIODevice * iod )".br.ti -1c.BI "QTextCodec * \fBloadCharmapFile\fR ( QString filename )".br.ti -1c.BI "QTextCodec * \fBcodecForMib\fR ( int mib )".br.ti -1c.BI "QTextCodec * \fBcodecForName\fR ( const char * name, int accuracy = 0 )".br.ti -1c.BI "QTextCodec * \fBcodecForContent\fR ( const char * chars, int len )".br.ti -1c.BI "QTextCodec * \fBcodecForIndex\fR ( int i )".br.ti -1c.BI "QTextCodec * \fBcodecForLocale\fR ()".br.ti -1c.BI "void \fBsetCodecForLocale\fR ( QTextCodec * c )".br.ti -1c.BI "QTextCodec * \fBcodecForTr\fR ()".br.ti -1c.BI "void \fBsetCodecForTr\fR ( QTextCodec * c )".br.ti -1c.BI "QTextCodec * \fBcodecForCStrings\fR ()".br.ti -1c.BI "void \fBsetCodecForCStrings\fR ( QTextCodec * c )".br.ti -1c.BI "void \fBdeleteAllCodecs\fR ()".br.ti -1c.BI "const char * \fBlocale\fR ()".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "\fBQTextCodec\fR ()".br.in -1c.SS "Static Protected Members".in +1c.ti -1c.BI "int \fBsimpleHeuristicNameMatch\fR ( const char * name, const char * hint )".br.in -1c.SH DESCRIPTIONThe QTextCodec class provides conversion between text encodings..PPQt uses Unicode to store, draw and manipulate strings. In many situations you may wish to deal with data that uses a different encoding. For example, most japanese documents are still stored in Shift-JIS or ISO2022, while Russian users often have their documents in KOI8-R or CP1251..PPQt provides a set of QTextCodec classes to help with converting non-Unicode formats to and from Unicode. You can also create your own codec classes (see later)..PPThe supported encodings are:.TPLatin1.TPBig5 -- Chinese.TPBig5-HKSCS -- Chinese.TPeucJP -- Japanese.TPeucKR -- Korean.TPGB2312 -- Chinese.TPGBK -- Chinese.TPGB18030 -- Chinese.TPJIS7 -- Japanese.TPShift-JIS -- Japanese.TPTSCII -- Tamil.TPutf8 -- Unicode, 8-bit.TPutf16 -- Unicode.TPKOI8-R -- Russian.TPKOI8-U -- Ukrainian.TPISO8859-1 -- Western.TPISO8859-2 -- Central European.TPISO8859-3 -- Central European.TPISO8859-4 -- Baltic.TPISO8859-5 -- Cyrillic.TPISO8859-6 -- Arabic.TPISO8859-7 -- Greek.TPISO8859-8 -- Hebrew, visually ordered.TPISO8859-8-i -- Hebrew, logically ordered.TPISO8859-9 -- Turkish.TPISO8859-10.TPISO8859-13.TPISO8859-14.TPISO8859-15 -- Western.TPIBM 850.TPIBM 866.TPCP874.TPCP1250 -- Central European.TPCP1251 -- Cyrillic.TPCP1252 -- Western.TPCP1253 -- Greek.TPCP1254 -- Turkish.TPCP1255 -- Hebrew.TPCP1256 -- Arabic.TPCP1257 -- Baltic.TPCP1258.TPApple Roman.TPTIS-620 -- Thai.PPQTextCodecs can be used as follows to convert some locally encoded string to Unicode. Suppose you have some string encoded in Russian KOI8-R encoding, and want to convert it to Unicode. The simple way to do this is:.PP.nf.br QCString locallyEncoded = "..."; // text to convert.br QTextCodec *codec = QTextCodec::codecForName("KOI8-R"); // get the codec for KOI8-R.br QString unicodeString = codec->toUnicode( locallyEncoded );.br.fi.PPAfter this, \fCunicodeString\fR holds the text converted to Unicode. Converting a string from Unicode to the local encoding is just as easy:.PP.nf.br QString unicodeString = "..."; // any Unicode text.br QTextCodec *codec = QTextCodec::codecForName("KOI8-R"); // get the codec for KOI8-R.br QCString locallyEncoded = codec->fromUnicode( unicodeString );.br.fi.PPSome care must be taken when trying to convert the data in chunks, for example, when receiving it over a network. In such cases it is possible that a multi-byte character will be split over two chunks. At best this might result in the loss of a character and at worst cause the entire conversion to fail..PPThe approach to use in these situations is to create a QTextDecoder object for the codec and use this QTextDecoder for the whole decoding process, as shown below:.PP.nf.br QTextCodec *c = QTextCodec::codecForName( "Shift-JIS" );.br QTextDecoder *decoder = c->makeDecoder();.br.br QString unicodeString;.br while( receiving_data ) {.br QByteArray chunk = new_data;.br unicodeString += decoder->toUnicode( chunk.data(), chunk.length() );.br }.br.fi.PPThe QTextDecoder object maintains state between chunks and therefore works correctly even if a multi-byte character is split between chunks..SH "Creating your own Codec class"By making objects of subclasses of QTextCodec, support for new text encodings can be added to Qt..PPMore recently created QTextCodec objects take precedence over earlier ones..PPYou may find it more convenient to make your codec class available as a plugin; see the plugin documentation for more details..PPThe abstract virtual functions describe the encoder to the system and the coder is used as required in the different text file formats supported by QTextStream, and under X11, for the locale-specific character input and output..PPTo add support for another 8-bit encoding to Qt, make a subclass of QTextCodec and implement at least the following methods:.PP.nf.br const char* name() const.br.fiReturn the official name for the encoding..PP.nf
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -