QTextCodec Class Reference |
Function | Description |
---|---|
name() | Returns the official name for the encoding. If the ncoding is listed in the IANA character-sets encoding file, the name should be the preferred MIME name for the encoding. |
aliases() | Returns a list of alternative names for the encoding. QTextCodec provides a default implementation that returns an empty list. For example, "ISO-8859-1" has "latin1", "CP819", "IBM819", and "iso-ir-100" as aliases. |
mibEnum() | Return the MIB enum for the encoding if it is listed in the IANA character-sets encoding file. |
convertToUnicode() | Converts an 8-bit character string to Unicode. |
convertFromUnicode() | Converts a Unicode string to an 8-bit character string. |
You may find it more convenient to make your codec class available as a plugin; see How to Create Qt Plugins for details.
See also QTextStream, QTextDecoder, QTextEncoder, and Codecs Example.
Constant | Value | Description |
---|---|---|
QTextCodec::DefaultConversion | 0 | No flag is set. |
QTextCodec::ConvertInvalidToNull | 0x80000000 | If this flag is set, invalid input results in an empty string. |
QTextCodec::IgnoreHeader | 0x1 | Ignore any Unicode byte-order mark and don't generate any. |
The ConversionFlags type is a typedef for QFlags<ConversionFlag>. It stores an OR combination of ConversionFlag values.
Constructs a QTextCodec, and gives it the highest precedence. The QTextCodec should always be constructed on the heap (i.e. with new). Qt takes ownership and will delete it when the application terminates.
Warning: This function is not reentrant.
Destroys the QTextCodec. Note that you should not delete codecs yourself: once created they become Qt's responsibility.
Warning: This function is not reentrant.
Subclasses can return a number of aliases for the codec in question.
Standard aliases for codecs can be found in the IANA character-sets encoding file.
Returns the list of all available codecs, by name. Call QTextCodec::codecForName() to obtain the QTextCodec for the name.
The list may contain many mentions of the same codec if the codec has aliases.
See also availableMibs(), name(), and aliases().
Returns the list of MIBs for all available codecs. Call QTextCodec::codecForMib() to obtain the QTextCodec for the MIB.
See also availableCodecs() and mibEnum().
Returns true if the Unicode character ch can be fully encoded with this codec; otherwise returns false.
This is an overloaded member function, provided for convenience.
s contains the string being tested for encode-ability.
Returns the codec used by QString to convert to and from const char * and QByteArrays. If this function returns 0 (the default), QString assumes Latin-1.
See also setCodecForCStrings().
Tries to detect the encoding of the provided snippet of html in the given byte array, ba, and returns a QTextCodec instance that is capable of decoding the html to unicode. If the codec cannot be detected from the content provided, defaultCodec is returned.
This function was introduced in Qt 4.4.
This is an overloaded member function, provided for convenience.
If the codec cannot be detected, this overload returns a Latin-1 QTextCodec.
Returns a pointer to the codec most suitable for this locale.
On Windows, the codec will be based on a system locale. On Unix systems, starting with Qt 4.2, the codec will be using the iconv library. Note that in both cases the codec's name will be "System".
See also setCodecForLocale().
Returns the QTextCodec which matches the MIBenum mib.
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.
This is an overloaded member function, provided for convenience.
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.
Returns the codec used by QObject::tr() on its argument. If this function returns 0 (the default), tr() assumes Latin-1.
See also setCodecForTr().
QTextCodec subclasses must reimplement this function.
Converts the first number of characters from the input array from Unicode to the encoding of the subclass, and returns the result in a QByteArray.
state can be 0 in which case the conversion is stateless and default conversion rules should be used. If state is not 0, the codec should save the state after the conversion in state, and adjust the remainingChars and invalidChars members of the struct.
QTextCodec subclasses must reimplement this function.
Converts the first len characters of chars from the encoding of the subclass to Unicode, and returns the result in a QString.
state can be 0, in which case the conversion is stateless and default conversion rules should be used. If state is not 0, the codec should save the state after the conversion in state, and adjust the remainingChars and invalidChars members of the struct.
Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray.
This is an overloaded member function, provided for convenience.
Converts the first number of characters from the input array from Unicode to the encoding of this codec, and returns the result in a QByteArray.
The state of the convertor used is updated.
Creates a QTextDecoder which stores enough state to decode chunks of char * data to create chunks of Unicode data.
The caller is responsible for deleting the returned object.
Creates a QTextEncoder which stores enough state to encode chunks of Unicode data as char * data.
The caller is responsible for deleting the returned object.
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.
QTextCodec subclasses must reimplement this function. It returns the name of the encoding supported by the subclass.
If the codec is registered as a character set in the IANA character-sets encoding file this method should return the preferred mime name for the codec if defined, otherwise its name.
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.
Warning: Some codecs do not preserve the characters in the ASCII range (0x00 to 0x7F). For example, the Japanese Shift-JIS encoding maps the backslash character (0x5A) to the Yen character. To avoid undesirable side-effects, we recommend avoiding such codecs with setCodecsForCString().
Warning: This function is not reentrant.
See also codecForCStrings() and setCodecForTr().
Set the codec to c; this will be returned by codecForLocale(). If is a null pointer, the codec is reset to the default.
This might be needed for some applications that want to use their own mechanism for setting the locale.
Setting this codec is not supported on DOS based Windows.
See also codecForLocale().
Sets the codec used by QObject::tr() on its argument to c. If c is 0 (the default), tr() assumes Latin-1.
If 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:
int main(int argc, char *argv[]) { QApplication app(argc, argv); QTextCodec::setCodecForTr(QTextCodec::codecForName("eucKR")); ... }
Note that this is not the way to select the encoding that the user 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 Internationalization with Qt.
Warning: This function is not reentrant.
See also codecForTr() and setCodecForCStrings().
Converts a from the encoding of this codec to Unicode, and returns the result in a QString.
This is an overloaded member function, provided for convenience.
Converts the first size characters from the input from the encoding of this codec to Unicode, and returns the result in a QString.
The state of the convertor used is updated.
This is an overloaded member function, provided for convenience.
chars contains the source characters.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.4 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com