📄 qtextcodec.3qt
字号:
.br int mibEnum() const.br.fiReturn the MIB enum for the encoding if it is listed in the IANA character-sets encoding file..PPIf the encoding is multi-byte then it will have "state"; that is, the interpretation of some bytes will be dependent on some preceding bytes. For such encodings, you must implement:.PP.nf.br QTextDecoder* makeDecoder() const.br.fiReturn a QTextDecoder that remembers incomplete multi-byte sequence prefixes or other required state..PPIf the encoding does \fInot\fR require state, you should implement:.PP.nf.br QString toUnicode(const char* chars, int len) const.br.fiConverts \fIlen\fR characters from \fIchars\fR to Unicode..PPThe base QTextCodec class has default implementations of the above two functions, \fIbut they are mutually recursive\fR, so you must re-implement at least one of them, or both for improved efficiency..PPFor conversion from Unicode to 8-bit encodings, it is rarely necessary to maintain state. However, two functions similar to the two above are used for encoding:.PP.nf.br QTextEncoder* makeEncoder() const.br.fiReturn a QTextEncoder..PP.nf.br QCString fromUnicode(const QString& uc, int& lenInOut ) const.br.fiConverts \fIlenInOut\fR characters (of type QChar) from the start of the string \fIuc\fR, returning a QCString result, and also returning the length of the result in \fIlenInOut\fR..PPAgain, these are mutually recursive so only one needs to be implemented, or both if greater efficiency is possible..PPFinally, you must implement:.PP.nf.br int heuristicContentMatch(const char* chars, int len) const.br.fiGives a value indicating how likely it is that \fIlen\fR characters from \fIchars\fR are in the encoding..PPA good model for this function is the QWindowsLocalCodec::heuristicContentMatch function found in the Qt sources..PPA QTextCodec subclass might have improved performance if you also re-implement:.PP.nf.br bool canEncode( QChar ) const.br.fiTest if a Unicode character can be encoded..PP.nf.br bool canEncode( const QString& ) const.br.fiTest if a string of Unicode characters can be encoded..PP.nf.br int heuristicNameMatch(const char* hint) const.br.fiTest if a possibly non-standard name is referring to the codec..PPCodecs can also be created as plugins..PPSee also Internationalization with Qt..SH MEMBER FUNCTION DOCUMENTATION.SH "QTextCodec::QTextCodec ()\fC [protected]\fR"\fBWarning:\fR This function is \fInot\fR reentrant.</p>.PPConstructs a QTextCodec, and gives it the highest precedence. The QTextCodec should always be constructed on the heap (i.e. with new()), and once constructed it becomes the responsibility of Qt to delete it (which is done at QApplication destruction)..SH "QTextCodec::~QTextCodec ()\fC [virtual]\fR"\fBWarning:\fR This function is \fInot\fR reentrant.</p>.PPDestroys the QTextCodec. Note that you should not delete codecs yourself: once created they become Qt's responsibility..SH "bool QTextCodec::canEncode ( QChar ch ) const\fC [virtual]\fR"Returns TRUE if the unicode character \fIch\fR can be fully encoded with this codec; otherwise returns FALSE. The default implementation tests if the result of toUnicode(fromUnicode(ch)) is the original \fIch\fR. Subclasses may be able to improve the efficiency..SH "bool QTextCodec::canEncode ( const QString & s ) const\fC [virtual]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIs\fR contains the string being tested for encode-ability..SH "QTextCodec * QTextCodec::codecForCStrings ()\fC [static]\fR"Returns the codec used by QString to convert to and from const char* and QCStrings. If this function returns 0 (the default), QString assumes Latin-1..PPSee also setCodecForCStrings()..SH "QTextCodec * QTextCodec::codecForContent ( const char * chars, int len )\fC [static]\fR"Searches all installed QTextCodec objects, returning the one which most recognizes the given content. May return 0..PPNote that this is often a poor choice, since character encodings often use most of the available character sequences, and so only by linguistic analysis could a true match be made..PP\fIchars\fR contains the string to check, and \fIlen\fR contains the number of characters in the string to use..PPSee also heuristicContentMatch()..PPExample: qwerty/qwerty.cpp..SH "QTextCodec * QTextCodec::codecForIndex ( int i )\fC [static]\fR"Returns the QTextCodec \fIi\fR positions from the most recently inserted codec, or 0 if there is no such QTextCodec. Thus, codecForIndex(0) returns the most recently created QTextCodec..PPExample: qwerty/qwerty.cpp..SH "QTextCodec * QTextCodec::codecForLocale ()\fC [static]\fR"Returns a pointer to the codec most suitable for this locale..PPExample: qwerty/qwerty.cpp..SH "QTextCodec * QTextCodec::codecForMib ( int mib )\fC [static]\fR"Returns the QTextCodec which matches the MIBenum \fImib\fR..SH "QTextCodec * QTextCodec::codecForName ( const char * name, int accuracy = 0 )\fC [static]\fR"Searches all installed QTextCodec objects and returns the one which best matches \fIname\fR; the match is case-insensitive. Returns 0 if no codec's heuristicNameMatch() reports a match better than \fIaccuracy\fR, or if \fIname\fR is a null string..PPSee also heuristicNameMatch()..SH "QTextCodec * QTextCodec::codecForTr ()\fC [static]\fR"Returns the codec used by QObject::tr() on its argument. If this function returns 0 (the default), tr() assumes Latin-1..PPSee also setCodecForTr()..SH "void QTextCodec::deleteAllCodecs ()\fC [static]\fR"Deletes all the created codecs..PP\fBWarning:\fR Do not call this function..PPQApplication calls this just before exiting, to delete any QTextCodec objects that may be lying around. Since various other classes hold pointers to QTextCodec objects, it is not safe to call this function earlier..PPIf you are using the utility classes (like QString) but not using QApplication, calling this function at the very end of your application can be helpful to chase down memory leaks, as QTextCodec objects will not show up..SH "QCString QTextCodec::fromUnicode ( const QString & uc, int & lenInOut ) const\fC [virtual]\fR"Subclasses of QTextCodec must reimplement either this function or makeEncoder(). It converts the first \fIlenInOut\fR characters of \fIuc\fR from Unicode to the encoding of the subclass. If \fIlenInOut\fR is negative or too large, the length of \fIuc\fR is used instead..PPConverts \fIlenInOut\fR characters (not bytes) from \fIuc\fR, producing a QCString. \fIlenInOut\fR will be set to the length of the result (in bytes)..PPThe default implementation makes an encoder with makeEncoder() and converts the input with that. Note that the default makeEncoder() implementation makes an encoder that simply calls this function, hence subclasses \fImust\fR reimplement one function or the other to avoid infinite recursion..PPReimplemented in QHebrewCodec..SH "QCString QTextCodec::fromUnicode ( const QString & uc ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIuc\fR is the unicode source string..SH "int QTextCodec::heuristicContentMatch ( const char * chars, int len ) const\fC [pure virtual]\fR"Subclasses of QTextCodec must reimplement this function. It examines the first \fIlen\fR bytes of \fIchars\fR and returns a value indicating how likely it is that the string is a prefix of text encoded in the encoding of the subclass. A negative return value indicates that the text is detectably not in the encoding (e.g. it contains characters undefined in the encoding). A return value of 0 indicates that the text should be decoded with this codec rather than as ASCII, but there is no particular evidence. The value should range up to \fIlen\fR. Thus, most decoders will return -1, 0, or -\fIlen\fR..PPThe characters are not null terminated..PPSee also codecForContent()..SH "int QTextCodec::heuristicNameMatch ( const char * hint ) const\fC [virtual]\fR"Returns a value indicating how likely it is that this decoder is appropriate for decoding some format that has the given name. The name is compared with the \fIhint\fR..PPA good match returns a positive number around the length of the string. A bad match is negative..PPThe default implementation calls simpleHeuristicNameMatch() with the name of the codec..SH "QTextCodec * QTextCodec::loadCharmap ( QIODevice * iod )\fC [static]\fR"Reads a POSIX2 charmap definition from \fIiod\fR. The parser recognizes the following lines:.PP<font name="sans"> <code_set_name> \fIname\fR</br> <escape_char> \fIcharacter\fR</br> % alias \fIalias\fR</br> CHARMAP</br> <\fItoken\fR> /x\fIhexbyte\fR <U\fIunicode\fR> ...</br> <\fItoken\fR> /d\fIdecbyte\fR <U\fIunicode\fR> ...</br> <\fItoken\fR> /\fIoctbyte\fR <U\fIunicode\fR> ...</br> <\fItoken\fR> /\fIany\fR/\fIany\fR... <U\fIunicode\fR> ...</br> END CHARMAP</br> </font>.PPThe resulting QTextCodec is returned (and also added to the global list of codecs). The name() of the result is taken from the code_set_name..PPNote that a codec constructed in this way uses much more memory and is slower than a hand-written QTextCodec subclass, since tables in code are in memory shared by all applications simultaneously using Qt..PPSee also loadCharmapFile()..PPExample: qwerty/qwerty.cpp..SH "QTextCodec * QTextCodec::loadCharmapFile ( QString filename )\fC [static]\fR"A convenience function for loadCharmap() that loads the charmap definition from the file \fIfilename\fR..SH "const char * QTextCodec::locale ()\fC [static]\fR"Returns a string representing the current language..PPExample: i18n/main.cpp..SH "QTextDecoder * QTextCodec::makeDecoder () const\fC [virtual]\fR"Creates a QTextDecoder which stores enough state to decode chunks of char* data to create chunks of Unicode data. The default implementation creates a stateless decoder, which is sufficient for only the simplest encodings where each byte corresponds to exactly one Unicode character..PPThe caller is responsible for deleting the returned object..SH "QTextEncoder * QTextCodec::makeEncoder () const\fC [virtual]\fR"Creates a QTextEncoder which stores enough state to encode chunks of Unicode data as char* data. The default implementation creates a stateless encoder, which is sufficient for only the simplest encodings where each Unicode character corresponds to exactly one character..PPThe caller is responsible for deleting the returned object..SH "int QTextCodec::mibEnum () const\fC [pure virtual]\fR"Subclasses of QTextCodec must reimplement this function. It returns the MIBenum (see the IANA character-sets encoding file for more information). It is important that each QTextCodec subclass returns the correct unique value for this function..PPReimplemented in QEucJpCodec..SH "const char * QTextCodec::mimeName () const\fC [virtual]\fR"Returns the preferred mime name of the encoding as defined in the IANA character-sets encoding file..PPReimplemented in QEucJpCodec, QEucKrCodec, QJisCodec, QHebrewCodec, and QSjisCodec..SH "const char * QTextCodec::name () const\fC [pure virtual]\fR"Subclasses of QTextCodec must reimplement this function. It returns the name of the encoding supported by the subclass. When choosing a name for an encoding, consider these points:.TPOn X11, heuristicNameMatch( const char * hint ) is used to test if a the QTextCodec can convert between Unicode and the encoding of a font with encoding \fIhint\fR, such as "iso8859-1" for Latin-1 fonts," koi8-r" for Russian KOI8 fonts. The default algorithm of heuristicNameMatch() uses name()..TPSome applications may use this function to present encodings to the end user..PPExample: qwerty/qwerty.cpp..SH "void QTextCodec::setCodecForCStrings ( QTextCodec * c )\fC [static]\fR"\fBWarning:\fR This function is \fInot\fR reentrant.</p>.PPSets the codec used by QString to convert to and from const char* and QCStrings. If \fIc\fR is 0 (the default), QString assumes Latin-1..PPSee also codecForCStrings() and setCodecForTr()..SH "void QTextCodec::setCodecForLocale ( QTextCodec * c )\fC [static]\fR"Set the codec to \fIc\fR; this will be returned by codecForLocale(). This might be needed for some applications that want to use their own mechanism for setting the locale..PPSee also codecForLocale()..SH "void QTextCodec::setCodecForTr ( QTextCodec * c )\fC [static]\fR"\fBWarning:\fR This function is \fInot\fR reentrant.</p>.PPSets the codec used by QObject::tr() on its argument to \fIc\fR. If \fIc\fR is 0 (the default), tr() assumes Latin-1..PPIf the literal quoted text in the program is not in the Latin-1 encoding, this function can be used to set the appropriate encoding. For example, software developed by Korean programmers might use eucKR for all the text in the program, in which case the main() function might look like this:.PP.nf.br int main(int argc, char** argv).br {.br QApplication app(argc, argv);.br ... install any additional codecs ....br QTextCodec::setCodecForTr( QTextCodec::codecForName("eucKR") );.br ....br }.br.fi.PPNote that this is not the way to select the encoding that the \fIuser\fR has chosen. For example, to convert an application containing literal English strings to Korean, all that is needed is for the English strings to be passed through tr() and for translation files to be loaded. For details of internationalization, see the Qt internationalization documentation..PPSee also codecForTr() and setCodecForCStrings()..SH "int QTextCodec::simpleHeuristicNameMatch ( const char * name, const char * hint )\fC [static protected]\fR"A simple utility function for heuristicNameMatch(): it does some very minor character-skipping so that almost-exact matches score high. \fIname\fR is the text we're matching and \fIhint\fR is used for the comparison..SH "QString QTextCodec::toUnicode ( const char * chars, int len ) const\fC [virtual]\fR"Subclasses of QTextCodec must reimplement this function or makeDecoder(). It converts the first \fIlen\fR characters of \fIchars\fR to Unicode..PPThe default implementation makes a decoder with makeDecoder() and converts the input with that. Note that the default makeDecoder() implementation makes a decoder that simply calls this function, hence subclasses \fImust\fR reimplement one function or the other to avoid infinite recursion..SH "QString QTextCodec::toUnicode ( const QByteArray & a, int len ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIa\fR contains the source characters; \fIlen\fR contains the number of characters in \fIa\fR to use..SH "QString QTextCodec::toUnicode ( const QByteArray & a ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIa\fR contains the source characters..SH "QString QTextCodec::toUnicode ( const QCString & a, int len ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIa\fR contains the source characters; \fIlen\fR contains the number of characters in \fIa\fR to use..SH "QString QTextCodec::toUnicode ( const QCString & a ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIa\fR contains the source characters..SH "QString QTextCodec::toUnicode ( const char * chars ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIchars\fR contains the source characters..SH "SEE ALSO".BR http://doc.trolltech.com/qtextcodec.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qtextcodec.3qt) and the Qtversion (3.1.1).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -