Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QChar Class Reference

The QChar class provides a 16-bit Unicode character. More...

    #include <QChar>

Note: All the functions in this class are reentrant.

- List of all members, including inherited members
- Compatibility members

### Public Types

- enum Category { Mark_NonSpacing, Mark_SpacingCombining, Mark_Enclosing, Number_DecimalDigit, Number_Letter, ..., Punctuation_Dask }
- enum CombiningClass { Combining_Above, Combining_AboveAttached, Combining_AboveLeft, Combining_AboveLeftAttached, Combining_AboveRight, ..., Combining_RightAttached }
- enum Decomposition { NoDecomposition, Canonical, Circle, Compat, Final, ..., Wide }
- enum Direction { DirAL, DirAN, DirB, DirBN, DirCS, ..., DirWS }
- enum Joining { Center, Dual, OtherJoining, Right }
- enum SpecialCharacter { Null, Nbsp, ReplacementCharacter, ObjectReplacementCharacter, ByteOrderMark, ..., LineSeparator }
- enum UnicodeVersion { Unassigned, Unicode_1_1, Unicode_2_0, Unicode_2_1_2, Unicode_3_0, ..., Unicode_4_0 }

### Public Functions

- QChar ()
- QChar ( char ch )
- QChar ( uchar ch )
- QChar ( QLatin1Char ch )
- QChar ( uchar cell, uchar row )
- QChar ( ushort code )
- QChar ( short code )
- QChar ( uint code )
- QChar ( int code )
- QChar ( SpecialCharacter ch )
- const char ascii () const
- Category category () const
- uchar cell () const
- unsigned char combiningClass () const
- QString decomposition () const
- Decomposition decompositionTag () const
- int digitValue () const
- Direction direction () const
- bool hasMirrored () const
- bool isDigit () const
- bool isLetter () const
- bool isLetterOrNumber () const
- bool isMark () const
- bool isNull () const
- bool isNumber () const
- bool isPrint () const
- bool isPunct () const
- bool isSpace () const
- bool isSymbol () const
- Joining joining () const `(preliminary)`
- const char latin1 () const
- QChar mirroredChar () const
- uchar row () const
- QChar toLower () const
- QChar toUpper () const
- ushort & unicode ()
- const ushort unicode () const
- UnicodeVersion unicodeVersion () const

### Static Public Members

- QChar fromAscii ( char c )
- QChar fromLatin1 ( char c )

### Related Non-Members

- bool operator!= ( QChar c1, QChar c2 )
- bool operator< ( QChar c1, QChar c2 )
- QDataStream & operator<< ( QDataStream & out, const QChar & chr )
- bool operator<= ( QChar c1, QChar c2 )
- bool operator== ( QChar c1, QChar c2 )
- bool operator> ( QChar c1, QChar c2 )
- bool operator>= ( QChar c1, QChar c2 )
- QDataStream & operator>> ( QDataStream & in, QChar & chr )

## Detailed Description

The QChar class provides a 16-bit Unicode character.

Unicode characters are (so far) 16-bit entities without any markup or structure. This class represents such an entity. It is lightweight, so it can be used everywhere. Most compilers treat it like a "short int". (In a few years, it may be necessary to make QChar 32-bit when more than 65536 Unicode code points have been defined and come into use.)

QChar provides a full complement of testing/classification functions, converting to and from other formats, converting from composed to decomposed Unicode, and trying to compare and case-convert if you ask it to.

The classification functions include functions like those in the standard C++ header <cctype> (formerly <ctype.h>), but operating on the full range of Unicode characters. They all return true if the character is a certain type of character; otherwise they return false. These classification functions are isNull() (returns true if the character is '\0'), isPrint() (true if the character is any sort of printable character, including whitespace), isPunct() (any sort of punctation), isMark() (Unicode Mark), isLetter() (a letter), isNumber() (any sort of numeric character, not just 0-9), isLetterOrNumber(), and isDigit() (decimal digits). All of these are wrappers around category() which return the Unicode-defined category of each character.

QChar also provides direction(), which indicates the "natural" writing direction of this character. The joining() function indicates how the character joins with its neighbors (needed mostly for Arabic) and finally hasMirrored(), which indicates whether the character needs to be mirrored when it is printed in its "unnatural" writing direction.

Composed Unicode characters (like &aring;) can be converted to decomposed Unicode ("a" followed by "ring above") by using decomposition().

In Unicode, comparison is not necessarily possible and case conversion is very difficult at best. Unicode, covering the "entire" world, also includes most of the world's case and sorting problems. operator==() and friends will do comparison based purely on the numeric Unicode value (code point) of the characters, and toUpper() and toLower() will do case changes when the character has a well-defined upper-/lower-case equivalent. For locale-dependent comparisons, use QString::localeAwareCompare().

The conversion functions include unicode() (to a scalar), latin1() (to scalar, but converts all non-Latin-1 characters to 0), row() (gives the Unicode row), cell() (gives the Unicode cell), digitValue() (gives the integer value of any of the numerous digit characters), and a host of constructors.

QChar provides constructors and cast operators that make it easy to convert to and from traditional 8-bit `char`s. If you defined `QT_NO_CAST_FROM_ASCII` and `QT_NO_CAST_TO_ASCII`, as explained in the QString documentation, you will need to explicitly call fromAscii() or fromLatin1(), or use QLatin1Char, to construct a QChar from an 8-bit `char`, and you will need to call ascii() or latin1() to get the 8-bit value back.

More information can be found in the document About Unicode.

See also QString.

## Member Type Documentation

### enum QChar::Category

This enum maps the Unicode character categories.

The following characters are normative in Unicode:

`QChar::Mark_NonSpacing` | Unicode class name Mn
`QChar::Mark_SpacingCombining` | Unicode class name Mc
`QChar::Mark_Enclosing` | Unicode class name Me
`QChar::Number_DecimalDigit` | Unicode class name Nd
`QChar::Number_Letter` | Unicode class name Nl
`QChar::Number_Other` | Unicode class name No
`QChar::Separator_Space` | Unicode class name Zs
`QChar::Separator_Line` | Unicode class name Zl
`QChar::Separator_Paragraph` | Unicode class name Zp
`QChar::Other_Control` | Unicode class name Cc
`QChar::Other_Format` | Unicode class name Cf
`QChar::Other_Surrogate` | Unicode class name Cs
`QChar::Other_PrivateUse` | Unicode class name Co
`QChar::Other_NotAssigned` | Unicode class name Cn

The following categories are informative in Unicode:

`QChar::Letter_Uppercase` | Unicode class name Lu
`QChar::Letter_Lowercase` | Unicode class name Ll
`QChar::Letter_Titlecase` | Unicode class name Lt
`QChar::Letter_Modifier` | Unicode class name Lm
`QChar::Letter_Other` | Unicode class name Lo
`QChar::Punctuation_Connector` | Unicode class name Pc
`QChar::Punctuation_Dash` | Unicode class name Pd
`QChar::Punctuation_Open` | Unicode class name Ps
`QChar::Punctuation_Close` | Unicode class name Pe
`QChar::Punctuation_InitialQuote` | Unicode class name Pi
`QChar::Punctuation_FinalQuote` | Unicode class name Pf
`QChar::Punctuation_Other` | Unicode class name Po
`QChar::Symbol_Math` | Unicode class name Sm
`QChar::Symbol_Currency` | Unicode class name Sc
`QChar::Symbol_Modifier` | Unicode class name Sk
`QChar::Symbol_Other` | Unicode class name So

There are two categories that are specific to Qt:

`QChar::NoCategory` | Qt cannot find an appropriate category for the character.
`QChar::Punctuation_Dask` | An alias for Punctuation_Dash

### enum QChar::CombiningClass

This enum type defines names for some of the Unicode combining classes. See the Unicode Standard for a description of the values.

`QChar::Combining_Above` |
`QChar::Combining_AboveAttached` |
`QChar::Combining_AboveLeft` |
`QChar::Combining_AboveLeftAttached` |
`QChar::Combining_AboveRight` |
`QChar::Combining_AboveRightAttached` |
`QChar::Combining_Below` |
`QChar::Combining_BelowAttached` |
`QChar::Combining_BelowLeft` |
`QChar::Combining_BelowLeftAttached` |
`QChar::Combining_BelowRight` |
`QChar::Combining_BelowRightAttached` |
`QChar::Combining_DoubleAbove` |
`QChar::Combining_DoubleBelow` |
`QChar::Combining_IotaSubscript` |
`QChar::Combining_Left` |
`QChar::Combining_LeftAttached` |
`QChar::Combining_Right` |
`QChar::Combining_RightAttached` |

### enum QChar::Decomposition

This enum type defines the Unicode decomposition attributes. See the Unicode Standard for a description of the values.

`QChar::NoDecomposition` |
`QChar::Canonical` |
`QChar::Circle` |
`QChar::Compat` |
`QChar::Final` |
`QChar::Font` |
`QChar::Fraction` |
`QChar::Initial` |
`QChar::Isolated` |
`QChar::Medial` |
`QChar::Narrow` |
`QChar::NoBreak` |
`QChar::Small` |
`QChar::Square` |
`QChar::Sub` |
`QChar::Super` |
`QChar::Vertical` |
`QChar::Wide` |

### enum QChar::Direction

This enum type defines the Unicode direction attributes. See the Unicode Standard for a description of the values.

In order to conform to C/C++ naming conventions "Dir" is prepended to the codes used in the Unicode Standard.

`QChar::DirAL` |
`QChar::DirAN` |
`QChar::DirB` |
`QChar::DirBN` |
`QChar::DirCS` |
`QChar::DirEN` |
`QChar::DirES` |
`QChar::DirET` |
`QChar::DirL` |
`QChar::DirLRE` |
`QChar::DirLRO` |
`QChar::DirNSM` |
`QChar::DirON` |
`QChar::DirPDF` |
`QChar::DirR` |
`QChar::DirRLE` |
`QChar::DirRLO` |
`QChar::DirS` |
`QChar::DirWS` |

### enum QChar::Joining

This enum type defines the Unicode joining attributes. See the Unicode Standard for a description of the values.

`QChar::Center` |
`QChar::Dual` |
`QChar::OtherJoining` |
`QChar::Right` |

### enum QChar::SpecialCharacter

`QChar::Null` | Character 0x0000 A QChar with this value isNull().
`QChar::Nbsp` | Non-breaking space
`QChar::ReplacementCharacter` |
`QChar::ObjectReplacementCharacter` |
`QChar::ByteOrderMark` |
`QChar::ByteOrderSwapped` |
`QChar::ParagraphSeparator` |
`QChar::LineSeparator` |

### enum QChar::UnicodeVersion

`QChar::Unassigned` |
`QChar::Unicode_1_1` |
`QChar::Unicode_2_0` |
`QChar::Unicode_2_1_2` |
`QChar::Unicode_3_0` |
`QChar::Unicode_3_1` |
`QChar::Unicode_3_2` |
`QChar::Unicode_4_0` |

## Member Function Documentation

### QChar::QChar ()

Constructs a null QChar ('\0').

See also isNull().

### QChar::QChar ( char ch )

Constructs a QChar corresponding to ASCII/Latin-1 character ch.

### QChar::QChar ( uchar ch )

Constructs a QChar corresponding to ASCII/Latin-1 character ch.

### QChar::QChar ( QLatin1Char ch )

Constructs a QChar corresponding to ASCII/Latin-1 character ch.

### QChar::QChar ( uchar cell, uchar row )

Constructs a QChar for Unicode cell cell in row row.

See also cell() and row().

### QChar::QChar ( ushort code )

Constructs a QChar for the character with Unicode code point code.

### QChar::QChar ( short code )

Constructs a QChar for the character with Unicode code point code.

### QChar::QChar ( uint code )

Constructs a QChar for the character with Unicode code point code.

### QChar::QChar ( int code )

Constructs a QChar for the character with Unicode code point code.

### QChar::QChar ( SpecialCharacter ch )

Constructs a QChar for the predefined character value ch.

### const char QChar::ascii () const

Returns the ASCII character value of the QChar, or 0 if the character is not representable as ASCII (i.e., if unicode() >= 128). This is mainly useful for non-internationalized software.

See also latin1(), unicode(), and QTextCodec::codecForCStrings().

### Category QChar::category () const

Returns the character's category.

### uchar QChar::cell () const

Returns the cell (least significant byte) of the Unicode character.

See also row().

### unsigned char QChar::combiningClass () const

Returns the combining class for the character as defined in the Unicode standard. This is mainly useful as a positioning hint for marks attached to a base character.

The Qt text rendering engine uses this information to correctly position non-spacing marks around a base character.

### QString QChar::decomposition () const

Decomposes a character into its parts. Returns an empty string if no decomposition exists.

### Decomposition QChar::decompositionTag () const

Returns the tag defining the composition of the character. Returns QChar::Single if no decomposition exists.

### int QChar::digitValue () const

Returns the numeric value of the digit, or -1 if the character is not a digit.

### Direction QChar::direction () const

Returns the character's direction.

### QChar QChar::fromAscii ( char c ) `[static]`

Converts the ascii character c to its equivalent QChar. This is mainly useful for non-internationalized software.

### An alternative is to use QLatin1Char().

See also fromLatin1(), unicode(), and QTextCodec::codecForCStrings().

### QChar QChar::fromLatin1 ( char c ) `[static]`

Converts the Latin-1 character c to its equivalent QChar. This is mainly useful for non-internationalized software.

See also fromAscii(), unicode(), and QTextCodec::codecForCStrings().

### bool QChar::hasMirrored () const

Returns true if the character should be reversed if the text direction is reversed; otherwise returns false.

See also mirroredChar().

### bool QChar::isDigit () const

Returns true if the character is a decimal digit (Number_DecimalDigit); otherwise returns false.

### bool QChar::isLetter () const

Returns true if the character is a letter (Letter_* categories); otherwise returns false.

### bool QChar::isLetterOrNumber () const

Returns true if the character is a letter or number (Letter_* or Number_* categories); otherwise returns false.

### bool QChar::isMark () const

Returns true if the character is a mark (Mark_* categories); otherwise returns false.

### bool QChar::isNull () const

Returns true if the character is the Unicode character 0x0000 ('\0'); otherwise returns false.

### bool QChar::isNumber () const

Returns true if the character is a number (Number_* categories, not just 0-9); otherwise returns false.

See also isDigit().

### bool QChar::isPrint () const

Returns true if the character is a printable character; otherwise returns false. This is any character not of category Cc or Cn.

Note that this gives no indication of whether the character is available in a particular font.

### bool QChar::isPunct () const

Returns true if the character is a punctuation mark (Punctuation_* categories); otherwise returns false.

### bool QChar::isSpace () const

Returns true if the character is a separator character (Separator_* categories); otherwise returns false.

### bool QChar::isSymbol () const

Returns true if the character is a symbol (Symbol_* categories); otherwise returns false.

### Joining QChar::joining () const

This function is under development and is subject to change.

Returns information about the joining properties of the character (needed for certain languages such as Arabic).

### const char QChar::latin1 () const

Returns the Latin-1 character equivalent to the QChar, or 0. This is mainly useful for non-internationalized software.

See also ascii(), unicode(), and QTextCodec::codecForCStrings().

### QChar QChar::mirroredChar () const

Returns the mirrored character if this character is a mirrored character; otherwise returns the character itself.

See also hasMirrored().

### uchar QChar::row () const

Returns the row (most significant byte) of the Unicode character.

See also cell().

### QChar QChar::toLower () const

Returns the lowercase equivalent if the character is uppercase; otherwise returns the character itself.

### QChar QChar::toUpper () const

Returns the uppercase equivalent if the character is lowercase; otherwise returns the character itself.

### ushort & QChar::unicode ()

Returns a reference to the numberic Unicode value of the QChar.

### const ushort QChar::unicode () const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

### UnicodeVersion QChar::unicodeVersion () const

Returns the Unicode version that introduced this character.

## Related Non-Members

### bool operator!= ( QChar c1, QChar c2 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns true if c1 and c2 are not the same Unicode character; otherwise returns false.

### bool operator< ( QChar c1, QChar c2 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns true if the numeric Unicode value of c1 is less than that of c2; otherwise returns false.

### QDataStream & operator<< ( QDataStream & out, const QChar & chr )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Writes the char chr to the stream out.

See also Format of the QDataStream operators.

### bool operator<= ( QChar c1, QChar c2 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns true if the numeric Unicode value of c1 is less than or equal to that of c2; otherwise returns false.

### bool operator== ( QChar c1, QChar c2 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns true if c1 and c2 are the same Unicode character; otherwise returns false.

### bool operator> ( QChar c1, QChar c2 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns true if the numeric Unicode value of c1 is greater than that of c2; otherwise returns false.

### bool operator>= ( QChar c1, QChar c2 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns true if the numeric Unicode value of c1 is greater than or equal to that of c2; otherwise returns false.

### QDataStream & operator>> ( QDataStream & in, QChar & chr )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Reads a char from the stream in into char chr.

See also Format of the QDataStream operators.