QTextCodec Class Reference

#include <qtextcodec.h>

Inheritance diagram for QTextCodec:

Inheritance graph
[legend]
Collaboration diagram for QTextCodec:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QTextCodec class provides conversions between text encodings. .

Qt 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 ISO 2022-JP, while Russian users often have their documents in KOI8-R or Windows-1251.

Qt 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.

The supported encodings are:

Apple Roman {Big5 Text Codec}{Big5} {Big5-HKSCS Text Codec}{Big5-HKSCS} {EUC-JP Text Codec}{EUC-JP} {EUC-KR Text Codec}{EUC-KR} {GBK Text Codec}{GB18030-0} IBM 850 IBM 866 IBM 874 {ISO 2022-JP (JIS) Text Codec}{ISO 2022-JP} ISO 8859-1 to 10 ISO 8859-13 to 16 Iscii-Bng, Dev, Gjr, Knd, Mlm, Ori, Pnj, Tlg, and Tml JIS X 0201 JIS X 0208 KOI8-R KOI8-U MuleLao-1 ROMAN8 {Shift-JIS Text Codec}{Shift-JIS} TIS-620 {TSCII Text Codec}{TSCII} UTF-8 UTF-16 UTF-16BE UTF-16LE Windows-1250 to 1258 WINSAMI2

QTextCodecs 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 it is like this:

        QByteArray encodedString = "...";
        QTextCodec *codec = QTextCodec::codecForName("KOI8-R");
        QString string = codec->toUnicode(encodedString);

After this, string holds the text converted to Unicode. Converting a string from Unicode to the local encoding is just as easy:

        QString string = "...";
        QTextCodec *codec = QTextCodec::codecForName("KOI8-R");
        QByteArray encodedString = codec->fromUnicode(string);

To read or write files in various encodings, use QTextStream and its {QTextStream::setCodec()}{setCodec()} function. See the {tools/codecs}{Codecs} example for an application of QTextCodec to file I/O.

Some 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.

The 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:

        QTextCodec *codec = QTextCodec::codecForName("Shift-JIS");
        QTextDecoder *decoder = codec->makeDecoder();

        QString string;
        while (new_data_available()) {
            QByteArray chunk = get_new_data();
            string += decoder->toUnicode(chunk);
        }

The QTextDecoder object maintains state between chunks and therefore works correctly even if a multi-byte character is split between chunks.

Support for new text encodings can be added to Qt by creating QTextCodec subclasses. The pure 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. To add support for another encoding to Qt, make a subclass of QTextCodec and implement the functions listed in the table below. \table \header \o Function \o Description \row \o name() \o Returns the official name for the encoding. If the ncoding is listed in the \l{http://www.iana.org/assignments/character-sets}{IANA character-sets encoding file}, the name should be the preferred MIME name for the encoding. \row \o aliases() \o 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. \row \o mibEnum() \o Return the MIB enum for the encoding if it is listed in the \l{http://www.iana.org/assignments/character-sets}{IANA character-sets encoding file}. \row \o convertToUnicode() \o Converts an 8-bit character string to Unicode. \row \o convertFromUnicode() \o Converts a Unicode string to an 8-bit character string. \endtable You may find it more convenient to make your codec class available as a plugin; see \l{How to Create Qt Plugins} for details. \sa QTextStream, QTextDecoder, QTextEncoder, {Codecs Example} Definition at line 42 of file qtextcodec.h.

Public Types

enum  ConversionFlag

Public Member Functions

QTextDecodermakeDecoder () const
QTextEncodermakeEncoder () const
bool canEncode (QChar) const
bool canEncode (const QString &) const
QString toUnicode (const QByteArray &) const
QString toUnicode (const char *chars) const
QByteArray fromUnicode (const QString &uc) const
QString toUnicode (const char *in, int length, ConverterState *state=0) const
QByteArray fromUnicode (const QChar *in, int length, ConverterState *state=0) const
virtual QByteArray name () const=0
virtual QList< QByteArrayaliases () const
virtual int mibEnum () const=0

Static Public Member Functions

static QTextCodeccodecForName (const QByteArray &name)
static QTextCodeccodecForName (const char *name)
static QTextCodeccodecForMib (int mib)
static QList< QByteArrayavailableCodecs ()
static QList< int > availableMibs ()
static QTextCodeccodecForLocale ()
static void setCodecForLocale (QTextCodec *c)
static QTextCodeccodecForTr ()
static void setCodecForTr (QTextCodec *c)
static QTextCodeccodecForCStrings ()
static void setCodecForCStrings (QTextCodec *c)
static QTextCodeccodecForHtml (const QByteArray &ba)

Protected Member Functions

virtual QString convertToUnicode (const char *in, int length, ConverterState *state) const=0
virtual QByteArray convertFromUnicode (const QChar *in, int length, ConverterState *state) const =0
 QTextCodec ()
virtual ~QTextCodec ()

Static Private Attributes

static QTextCodeccftr

Friends

class QTextCodecCleanup

Classes

struct  ConverterState


Member Enumeration Documentation

enum QTextCodec::ConversionFlag

DefaultConversion No flag is set. ConvertInvalidToNull If this flag is set, invalid input results in an empty string. IgnoreHeader Ignore any Unicode byte-order mark and don't generate any.

Definition at line 73 of file qtextcodec.h.

00073                         {
00074         DefaultConversion,
00075         ConvertInvalidToNull = 0x80000000,
00076         IgnoreHeader = 0x1
00077     };


Constructor & Destructor Documentation

QTextCodec::QTextCodec (  )  [protected]

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.

Definition at line 727 of file qtextcodec.cpp.

References QList< T >::prepend(), and setup().

00728 {
00729     setup();
00730     all->prepend(this);
00731 }

Here is the call graph for this function:

QTextCodec::~QTextCodec (  )  [protected, virtual]

Destroys the QTextCodec. Note that you should not delete codecs yourself: once created they become Qt's responsibility.

Definition at line 740 of file qtextcodec.cpp.

References qWarning(), and QList< T >::removeAll().

00741 {
00742     if (!destroying_is_ok)
00743         qWarning("QTextCodec::~QTextCodec: Called by application");
00744     if (all)
00745         all->removeAll(this);
00746 }

Here is the call graph for this function:


Member Function Documentation

QTextCodec * QTextCodec::codecForName ( const QByteArray name  )  [static]

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.

Definition at line 761 of file qtextcodec.cpp.

References aliases(), QList< T >::at(), i, QByteArray::isEmpty(), name(), setup(), and QList< T >::size().

Referenced by MainWindow::aboutToShowSaveAsMenu(), checkForCodec(), codec(), codecForHtml(), codecForHTML(), fetchtr_cpp(), TextEdit::fileSave(), QTextStreamPrivate::fillReadBuffer(), QXmlInputSource::fromRawData(), main(), Index::parseDocument(), qt_findcharset(), qt_set_input_encoding(), QPngHandlerPrivate::readPngHeader(), QMimeDataPrivate::retrieveTypedData(), ru_RU_hack(), PhraseBook::save(), MetaTranslator::save(), QDomDocumentPrivate::save(), QTextStream::setCodec(), MetaTranslator::setCodec(), setupLocaleMapper(), and startTokenizer().

00762 {
00763     if (name.isEmpty())
00764         return 0;
00765 
00766     setup();
00767 
00768     for (int i = 0; i < all->size(); ++i) {
00769         QTextCodec *cursor = all->at(i);
00770         if (nameMatch(cursor->name(), name))
00771             return cursor;
00772         QList<QByteArray> aliases = cursor->aliases();
00773         for (int i = 0; i < aliases.size(); ++i)
00774             if (nameMatch(aliases.at(i), name))
00775                 return cursor;
00776     }
00777 
00778     return createForName(name);
00779 }

Here is the call graph for this function:

QTextCodec * QTextCodec::codecForName ( const char *  name  )  [inline, static]

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.

Definition at line 47 of file qtextcodec.h.

00047 { return codecForName(QByteArray(name)); }

QTextCodec * QTextCodec::codecForMib ( int  mib  )  [static]

Returns the QTextCodec which matches the MIBenum mib.

Definition at line 786 of file qtextcodec.cpp.

References QList< T >::at(), i, setup(), and QList< T >::size().

Referenced by Q3TextStream::codec(), codecForHtml(), codecForHTML(), MainWindow::findCodecs(), QXmlInputSource::fromRawData(), QFontEngineXLFD::QFontEngineXLFD(), Q3TextStream::setEncoding(), thaiWordBreaks(), translateKeySym(), and PreviewForm::updateTextEdit().

00787 {
00788     setup();
00789 
00790     // Qt 3 used 1000 (mib for UCS2) as it's identifier for the utf16 codec. Map
00791     // this correctly for compatibility.
00792     if (mib == 1000)
00793         mib = 1015;
00794 
00795     QList<QTextCodec*>::ConstIterator i;
00796     for (int i = 0; i < all->size(); ++i) {
00797         QTextCodec *cursor = all->at(i);
00798         if (cursor->mibEnum() == mib)
00799             return cursor;
00800     }
00801 
00802     return createForMib(mib);
00803 }

Here is the call graph for this function:

QList< QByteArray > QTextCodec::availableCodecs (  )  [static]

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(), aliases()

Definition at line 814 of file qtextcodec.cpp.

References aliases(), QList< T >::at(), codecs, i, l, name(), setup(), QList< T >::size(), QString::startsWith(), and QString::toLatin1().

00815 {
00816     setup();
00817 
00818     QList<QByteArray> codecs;
00819     for (int i = 0; i < all->size(); ++i) {
00820         codecs += all->at(i)->name();
00821         codecs += all->at(i)->aliases();
00822     }
00823 #ifndef QT_NO_TEXTCODECPLUGIN
00824     QFactoryLoader *l = loader();
00825     QStringList keys = l->keys();
00826     for (int i = 0; i < keys.size(); ++i) {
00827         if (!keys.at(i).startsWith(QLatin1String("MIB: "))) {
00828             QByteArray name = keys.at(i).toLatin1();
00829             if (!codecs.contains(name))
00830                 codecs += name;
00831         }
00832     }
00833 #endif
00834 
00835     return codecs;
00836 }

Here is the call graph for this function:

QList< int > QTextCodec::availableMibs (  )  [static]

Returns the list of MIBs for all available codecs. Call QTextCodec::codecForMib() to obtain the QTextCodec for the MIB.

See also:
availableCodecs(), mibEnum()

Definition at line 844 of file qtextcodec.cpp.

References QList< T >::at(), codecs, i, l, mibEnum(), QString::mid(), setup(), QList< T >::size(), QString::startsWith(), and QString::toInt().

Referenced by MainWindow::findCodecs().

00845 {
00846     setup();
00847 
00848     QList<int> codecs;
00849     for (int i = 0; i < all->size(); ++i)
00850         codecs += all->at(i)->mibEnum();
00851 #ifndef QT_NO_TEXTCODECPLUGIN
00852     QFactoryLoader *l = loader();
00853     QStringList keys = l->keys();
00854     for (int i = 0; i < keys.size(); ++i) {
00855         if (keys.at(i).startsWith(QLatin1String("MIB: "))) {
00856             int mib = keys.at(i).mid(5).toInt();
00857             if (!codecs.contains(mib))
00858                 codecs += mib;
00859         }
00860     }
00861 #endif
00862 
00863     return codecs;
00864 }

Here is the call graph for this function:

QTextCodec * QTextCodec::codecForLocale (  )  [static]

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".

Definition at line 893 of file qtextcodec.cpp.

References localeMapper, and setup().

Referenced by codec(), QTextStreamPrivate::fillReadBuffer(), QTextStreamPrivate::flushWriteBuffer(), QString::fromLocal8Bit(), QFont::initialize(), QX11Data::motifdndFormat(), QX11Data::motifdndObtainData(), qstring_to_xtp(), qt_set_input_encoding(), QTextStreamPrivate::reset(), Q3TextStream::setEncoding(), and QString::toLocal8Bit().

00894 {
00895     if (localeMapper)
00896         return localeMapper;
00897 
00898     setup();
00899 
00900     return localeMapper;
00901 }

Here is the call graph for this function:

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

Set the codec to c; this will be returned by codecForLocale(). 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()

Definition at line 875 of file qtextcodec.cpp.

References c, and localeMapper.

00876 {
00877 #ifdef Q_WS_WIN
00878     if (QSysInfo::WindowsVersion& QSysInfo::WV_DOS_based)
00879   return;
00880 #endif
00881     localeMapper = c;
00882 }

QTextCodec * QTextCodec::codecForTr (  )  [inline, static]

Returns the codec used by QObject::tr() on its argument. If this function returns 0 (the default), tr() assumes Latin-1.

See also:
setCodecForTr()

Definition at line 126 of file qtextcodec.h.

Referenced by QCoreApplication::translate().

00126 { return cftr; }

void QTextCodec::setCodecForTr ( QTextCodec c  )  [inline, static]

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}.

See also:
codecForTr(), setCodecForCStrings()

Definition at line 127 of file qtextcodec.h.

References c, and cftr.

00127 { cftr = c; }

QTextCodec * QTextCodec::codecForCStrings (  )  [inline, static]

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()

Definition at line 128 of file qtextcodec.h.

References QString::codecForCStrings.

Referenced by QChar::fromAscii(), QChar::QChar(), and QChar::toAscii().

00128 { return QString::codecForCStrings; }

void QTextCodec::setCodecForCStrings ( QTextCodec codec  )  [inline, 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.

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().
See also:
codecForCStrings(), setCodecForTr()

Definition at line 129 of file qtextcodec.h.

References c, and QString::codecForCStrings.

QTextCodec * QTextCodec::codecForHtml ( const QByteArray ba  )  [static]

Definition at line 1306 of file qtextcodec.cpp.

References c, codecForMib(), codecForName(), header(), QString::indexOf(), int, QByteArray::left(), QString::mid(), QByteArray::size(), and QByteArray::toLower().

Referenced by Qt::codecForHtml(), and QMimeDataPrivate::retrieveTypedData().

01307 {
01308     // determine charset
01309     int mib = 4; // Latin-1
01310     int pos;
01311     QTextCodec *c = 0;
01312 
01313     if (ba.size() > 1 && (((uchar)ba[0] == 0xfe && (uchar)ba[1] == 0xff)
01314                           || ((uchar)ba[0] == 0xff && (uchar)ba[1] == 0xfe))) {
01315         mib = 1015; // utf16
01316     } else if (ba.size() > 2
01317              && (uchar)ba[0] == 0xef
01318              && (uchar)ba[1] == 0xbb
01319              && (uchar)ba[2] == 0xbf) {
01320         mib = 106; // utf-8
01321     } else {
01322         QByteArray header = ba.left(512).toLower();
01323         if ((pos = header.indexOf("http-equiv=")) != -1) {
01324             pos = header.indexOf("charset=", pos) + int(strlen("charset="));
01325             if (pos != -1) {
01326                 int pos2 = header.indexOf('\"', pos+1);
01327                 QByteArray cs = header.mid(pos, pos2-pos);
01328                 //            qDebug("found charset: %s", cs.data());
01329                 c = QTextCodec::codecForName(cs);
01330             }
01331         }
01332     }
01333     if (!c)
01334         c = QTextCodec::codecForMib(mib);
01335 
01336     return c;
01337 }

Here is the call graph for this function:

QTextDecoder * QTextCodec::makeDecoder (  )  const

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.

Definition at line 977 of file qtextcodec.cpp.

Referenced by QXmlInputSource::fromRawData().

00978 {
00979     return new QTextDecoder(this);
00980 }

QTextEncoder * QTextCodec::makeEncoder (  )  const

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.

Definition at line 989 of file qtextcodec.cpp.

00990 {
00991     return new QTextEncoder(this);
00992 }

bool QTextCodec::canEncode ( QChar  ch  )  const

Returns true if the Unicode character ch can be fully encoded with this codec; otherwise returns false.

Definition at line 1039 of file qtextcodec.cpp.

References convertFromUnicode(), ConvertInvalidToNull, QTextCodec::ConverterState::flags, and QTextCodec::ConverterState::invalidChars.

Referenced by MainWindow::aboutToShowSaveAsMenu(), and getToken().

01040 {
01041     ConverterState state;
01042     state.flags = ConvertInvalidToNull;
01043     convertFromUnicode(&ch, 1, &state);
01044     return (state.invalidChars == 0);
01045 }

Here is the call graph for this function:

bool QTextCodec::canEncode ( const QString s  )  const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. s contains the string being tested for encode-ability.

Definition at line 1052 of file qtextcodec.cpp.

References convertFromUnicode(), ConvertInvalidToNull, QTextCodec::ConverterState::flags, QTextCodec::ConverterState::invalidChars, and s.

01053 {
01054     ConverterState state;
01055     state.flags = ConvertInvalidToNull;
01056     convertFromUnicode(s.constData(), s.length(), &state);
01057     return (state.invalidChars == 0);
01058 }

Here is the call graph for this function:

QString QTextCodec::toUnicode ( const QByteArray a  )  const

Converts a from the encoding of this codec to Unicode, and returns the result in a QString.

Definition at line 1029 of file qtextcodec.cpp.

References a, and convertToUnicode().

Referenced by Q3TextDrag::decode(), QTextStreamPrivate::fillReadBuffer(), QChar::fromAscii(), QString::fromAscii_helper(), QString::fromLocal8Bit(), getToken(), TextEdit::load(), QChar::QChar(), QPngHandlerPrivate::readPngHeader(), QMimeDataPrivate::retrieveTypedData(), QTextBrowserPrivate::setSource(), toUnicode(), MetaTranslator::toUnicode(), QTextDecoder::toUnicode(), QFontEngineXLFD::toUnicode(), QCoreApplication::translate(), Q3TextStream::ts_getbuf(), Q3TextStream::ts_getline(), and QXIMInputContext::x11FilterEvent().

01030 {
01031     return convertToUnicode(a.constData(), a.length(), 0);
01032 }

Here is the call graph for this function:

QString QTextCodec::toUnicode ( const char *  chars  )  const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. chars contains the source characters.

Definition at line 1107 of file qtextcodec.cpp.

References convertToUnicode(), and qstrlen().

01108 {
01109     int len = qstrlen(chars);
01110     return convertToUnicode(chars, len, 0);
01111 }

Here is the call graph for this function:

QByteArray QTextCodec::fromUnicode ( const QString str  )  const

Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray.

Definition at line 1009 of file qtextcodec.cpp.

References QString::constData(), convertFromUnicode(), and QString::length().

Referenced by QTextStreamPrivate::flushWriteBuffer(), fromUnicode(), QTextEncoder::fromUnicode(), getToken(), qstring_to_xtp(), Q3FtpPI::startNextCmd(), QFontEngineXLFD::stringToCMap(), QChar::toAscii(), QString::toAscii(), QString::toLocal8Bit(), Q3TextStream::ts_putc(), and Q3TextStream::writeBlock().

01010 {
01011     return convertFromUnicode(str.constData(), str.length(), 0);
01012 }

Here is the call graph for this function:

QString QTextCodec::toUnicode ( const char *  input,
int  size,
ConverterState state = 0 
) const [inline]

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.

Definition at line 93 of file qtextcodec.h.

00094         { return convertToUnicode(in, length, state); }

QByteArray QTextCodec::fromUnicode ( const QChar input,
int  number,
ConverterState state = 0 
) const [inline]

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.

Definition at line 95 of file qtextcodec.h.

00096         { return convertFromUnicode(in, length, state); }

QByteArray QTextCodec::name (  )  const [pure virtual]

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.

Referenced by availableCodecs(), codecForName(), QTextStreamPrivate::fillReadBuffer(), MainWindow::findCodecs(), QTextStreamPrivate::flushWriteBuffer(), getToken(), QX11Data::motifdndFormat(), qToField(), and PreviewForm::setCodecList().

QList< QByteArray > QTextCodec::aliases (  )  const [virtual]

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.

Definition at line 934 of file qtextcodec.cpp.

Referenced by availableCodecs(), and codecForName().

00935 {
00936     return QList<QByteArray>();
00937 }

int QTextCodec::mibEnum (  )  const [pure virtual]

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.

Referenced by availableMibs(), Q3TextDrag::decode(), QFontEngineXLFD::faceId(), QFont::initialize(), qt_set_input_encoding(), Q3TextStream::readLine(), Q3TextStream::setCodec(), MetaTranslator::setCodec(), PreviewForm::setCodecList(), Q3TextStream::setEncoding(), and translateKeySym().

QString QTextCodec::convertToUnicode ( const char *  chars,
int  len,
ConverterState state 
) const [protected, pure virtual]

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.

Referenced by toUnicode().

QByteArray QTextCodec::convertFromUnicode ( const QChar input,
int  number,
ConverterState state 
) const [protected, pure virtual]

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.

Referenced by canEncode(), and fromUnicode().


Friends And Related Function Documentation

friend class QTextCodecCleanup [friend]

Definition at line 121 of file qtextcodec.h.


Member Data Documentation

QTextCodec * QTextCodec::cftr [static, private]

Definition at line 122 of file qtextcodec.h.

Referenced by setCodecForTr().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 19:22:25 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1