QChar Class

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

Header: #include <QChar>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

Note: All functions in this class are reentrant.

Public Types

enum Category { Mark_NonSpacing, Mark_SpacingCombining, Mark_Enclosing, Number_DecimalDigit, Number_Letter, …, Symbol_Other }
enum Decomposition { NoDecomposition, Canonical, Circle, Compat, Final, …, Wide }
enum Direction { DirAL, DirAN, DirB, DirBN, DirCS, …, DirWS }
enum JoiningType { Joining_None, Joining_Causing, Joining_Dual, Joining_Right, Joining_Left, Joining_Transparent }
enum Script { Script_Unknown, Script_Inherited, Script_Common, Script_Adlam, Script_Ahom, …, Script_ZanabazarSquare }
enum SpecialCharacter { Null, Tabulation, LineFeed, FormFeed, CarriageReturn, …, LastValidCodePoint }
enum UnicodeVersion { Unicode_1_1, Unicode_2_0, Unicode_2_1_2, Unicode_3_0, Unicode_3_1, …, Unicode_Unassigned }

Public Functions

QChar()
QChar(ushort code)
QChar(uchar cell, uchar row)
QChar(short code)
QChar(uint code)
QChar(int code)
QChar(QChar::SpecialCharacter ch)
QChar(QLatin1Char ch)
QChar(char16_t ch)
QChar(wchar_t ch)
QChar(char ch)
QChar(uchar ch)
QChar::Category category() const
uchar cell() const
unsigned char combiningClass() const
QString decomposition() const
QChar::Decomposition decompositionTag() const
int digitValue() const
QChar::Direction direction() const
bool hasMirrored() const
bool isDigit() const
bool isHighSurrogate() const
bool isLetter() const
bool isLetterOrNumber() const
bool isLowSurrogate() const
bool isLower() const
bool isMark() const
bool isNonCharacter() const
bool isNull() const
bool isNumber() const
bool isPrint() const
bool isPunct() const
bool isSpace() const
bool isSurrogate() const
bool isSymbol() const
bool isTitleCase() const
bool isUpper() const
QChar::JoiningType joiningType() const
QChar mirroredChar() const
uchar row() const
QChar::Script script() const
QChar toCaseFolded() const
char toLatin1() const
QChar toLower() const
QChar toTitleCase() const
QChar toUpper() const
char16_t unicode() const
char16_t &unicode()
QChar::UnicodeVersion unicodeVersion() const

Static Public Members

QChar::Category category(char32_t ucs4)
unsigned char combiningClass(char32_t ucs4)
QChar::UnicodeVersion currentUnicodeVersion()
QString decomposition(char32_t ucs4)
QChar::Decomposition decompositionTag(char32_t ucs4)
int digitValue(char32_t ucs4)
QChar::Direction direction(char32_t ucs4)
QChar fromLatin1(char c)
QChar fromUcs2(char16_t c)
R fromUcs4(char32_t c)
bool hasMirrored(char32_t ucs4)
char16_t highSurrogate(char32_t ucs4)
bool isDigit(char32_t ucs4)
bool isHighSurrogate(char32_t ucs4)
bool isLetter(char32_t ucs4)
bool isLetterOrNumber(char32_t ucs4)
bool isLowSurrogate(char32_t ucs4)
bool isLower(char32_t ucs4)
bool isMark(char32_t ucs4)
bool isNonCharacter(char32_t ucs4)
bool isNumber(char32_t ucs4)
bool isPrint(char32_t ucs4)
bool isPunct(char32_t ucs4)
bool isSpace(char32_t ucs4)
bool isSurrogate(char32_t ucs4)
bool isSymbol(char32_t ucs4)
bool isTitleCase(char32_t ucs4)
bool isUpper(char32_t ucs4)
QChar::JoiningType joiningType(char32_t ucs4)
char16_t lowSurrogate(char32_t ucs4)
char32_t mirroredChar(char32_t ucs4)
bool requiresSurrogates(char32_t ucs4)
QChar::Script script(char32_t ucs4)
char32_t surrogateToUcs4(char16_t high, char16_t low)
char32_t surrogateToUcs4(QChar high, QChar low)
char32_t toCaseFolded(char32_t ucs4)
char32_t toLower(char32_t ucs4)
char32_t toTitleCase(char32_t ucs4)
char32_t toUpper(char32_t ucs4)
QChar::UnicodeVersion unicodeVersion(char32_t ucs4)
bool operator!=(QChar c1, QChar c2)
bool operator<(QChar c1, QChar c2)
QDataStream &operator<<(QDataStream &out, 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)

Macros

Detailed Description

In Qt, Unicode characters are 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 an unsigned short.

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, not just for the ASCII range. 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. Some of these also calculate the derived properties (for example isSpace() returns true if the character is of category Separator_* or an exceptional code point from Other_Control category).

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

Composed Unicode characters (like ring) 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 uppercase/lowercase equivalent. For locale-dependent comparisons, use QString::localeAwareCompare().

The conversion functions include unicode() (to a scalar), toLatin1() (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 chars. 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 fromLatin1(), or use QLatin1Char, to construct a QChar from an 8-bit char, and you will need to call toLatin1() to get the 8-bit value back.

Starting with Qt 6.0, most QChar constructors are explicit. This is done to avoid dangerous mistakes when accidentally mixing integral types and strings. You can opt-out (and make these constructors implicit) by defining the macro QT_IMPLICIT_QCHAR_CONSTRUCTION.

For more information see "About the Unicode Character Database".

See also Unicode, QString, and QLatin1Char.

Member Type Documentation

enum QChar::Category

This enum maps the Unicode character categories.

The following characters are normative in Unicode:

ConstantValueDescription
QChar::Mark_NonSpacing0Unicode class name Mn
QChar::Mark_SpacingCombining1Unicode class name Mc
QChar::Mark_Enclosing2Unicode class name Me
QChar::Number_DecimalDigit3Unicode class name Nd
QChar::Number_Letter4Unicode class name Nl
QChar::Number_Other5Unicode class name No
QChar::Separator_Space6Unicode class name Zs
QChar::Separator_Line7Unicode class name Zl
QChar::Separator_Paragraph8Unicode class name Zp
QChar::Other_Control9Unicode class name Cc
QChar::Other_Format10Unicode class name Cf
QChar::Other_Surrogate11Unicode class name Cs
QChar::Other_PrivateUse12Unicode class name Co
QChar::Other_NotAssigned13Unicode class name Cn

The following categories are informative in Unicode:

ConstantValueDescription
QChar::Letter_Uppercase14Unicode class name Lu
QChar::Letter_Lowercase15Unicode class name Ll
QChar::Letter_Titlecase16Unicode class name Lt
QChar::Letter_Modifier17Unicode class name Lm
QChar::Letter_Other18Unicode class name Lo
QChar::Punctuation_Connector19Unicode class name Pc
QChar::Punctuation_Dash20Unicode class name Pd
QChar::Punctuation_Open21Unicode class name Ps
QChar::Punctuation_Close22Unicode class name Pe
QChar::Punctuation_InitialQuote23Unicode class name Pi
QChar::Punctuation_FinalQuote24Unicode class name Pf
QChar::Punctuation_Other25Unicode class name Po
QChar::Symbol_Math26Unicode class name Sm
QChar::Symbol_Currency27Unicode class name Sc
QChar::Symbol_Modifier28Unicode class name Sk
QChar::Symbol_Other29Unicode class name So

See also category().

enum QChar::Decomposition

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

ConstantValue
QChar::NoDecomposition0
QChar::Canonical1
QChar::Circle8
QChar::Compat16
QChar::Final6
QChar::Font2
QChar::Fraction17
QChar::Initial4
QChar::Isolated7
QChar::Medial5
QChar::Narrow13
QChar::NoBreak3
QChar::Small14
QChar::Square15
QChar::Sub10
QChar::Super9
QChar::Vertical11
QChar::Wide12

See also decomposition().

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.

ConstantValue
QChar::DirAL13
QChar::DirAN5
QChar::DirB7
QChar::DirBN18
QChar::DirCS6
QChar::DirEN2
QChar::DirES3
QChar::DirET4
QChar::DirFSI (since Qt 5.3)21
QChar::DirL0
QChar::DirLRE11
QChar::DirLRI (since Qt 5.3)19
QChar::DirLRO12
QChar::DirNSM17
QChar::DirON10
QChar::DirPDF16
QChar::DirPDI (since Qt 5.3)22
QChar::DirR1
QChar::DirRLE14
QChar::DirRLI (since Qt 5.3)20
QChar::DirRLO15
QChar::DirS8
QChar::DirWS9

See also direction().

enum QChar::JoiningType

since 5.3

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

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

ConstantValue
QChar::Joining_None0
QChar::Joining_Causing1
QChar::Joining_Dual2
QChar::Joining_Right3
QChar::Joining_Left4
QChar::Joining_Transparent5

See also joiningType().

enum QChar::Script

This enum type defines the Unicode script property values.

For details about the Unicode script property values see Unicode Standard Annex #24.

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

ConstantValueDescription
QChar::Script_Unknown0For unassigned, private-use, noncharacter, and surrogate code points.
QChar::Script_Inherited1For characters that may be used with multiple scripts and that inherit their script from the preceding characters. These include nonspacing marks, enclosing marks, and zero width joiner/non-joiner characters.
QChar::Script_Common2For characters that may be used with multiple scripts and that do not inherit their script from the preceding characters.
QChar::Script_Adlam (since Qt 5.11)132 
QChar::Script_Ahom (since Qt 5.6)126 
QChar::Script_AnatolianHieroglyphs (since Qt 5.6)127 
QChar::Script_Arabic8 
QChar::Script_Armenian6 
QChar::Script_Avestan80 
QChar::Script_Balinese62 
QChar::Script_Bamum84 
QChar::Script_BassaVah (since Qt 5.5)104 
QChar::Script_Batak93 
QChar::Script_Bengali12 
QChar::Script_Bhaiksuki (since Qt 5.11)133 
QChar::Script_Bopomofo36 
QChar::Script_Brahmi94 
QChar::Script_Braille54 
QChar::Script_Buginese55 
QChar::Script_Buhid44 
QChar::Script_CanadianAboriginal29 
QChar::Script_Carian75 
QChar::Script_CaucasianAlbanian (since Qt 5.5)103 
QChar::Script_Chakma96 
QChar::Script_Cham77 
QChar::Script_Cherokee28 
QChar::Script_Chorasmian (since Qt 5.15)153 
QChar::Script_Coptic46 
QChar::Script_Cuneiform63 
QChar::Script_Cypriot53 
QChar::Script_CyproMinoan (since Qt 6.3)157 
QChar::Script_Cyrillic5 
QChar::Script_Deseret41 
QChar::Script_Devanagari11 
QChar::Script_DivesAkuru (since Qt 5.15)154 
QChar::Script_Dogra (since Qt 5.15)142 
QChar::Script_Duployan (since Qt 5.5)105 
QChar::Script_EgyptianHieroglyphs81 
QChar::Script_Elbasan (since Qt 5.5)106 
QChar::Script_Elymaic (since Qt 5.15)149 
QChar::Script_Ethiopic27 
QChar::Script_Georgian25 
QChar::Script_Glagolitic57 
QChar::Script_Gothic40 
QChar::Script_Grantha (since Qt 5.5)107 
QChar::Script_Greek4 
QChar::Script_Gujarati14 
QChar::Script_GunjalaGondi (since Qt 5.15)143 
QChar::Script_Gurmukhi13 
QChar::Script_Han37 
QChar::Script_Hangul26 
QChar::Script_HanifiRohingya (since Qt 5.15)144 
QChar::Script_Hanunoo43 
QChar::Script_Hatran (since Qt 5.6)128 
QChar::Script_Hebrew7 
QChar::Script_Hiragana34 
QChar::Script_ImperialAramaic87 
QChar::Script_InscriptionalPahlavi90 
QChar::Script_InscriptionalParthian89 
QChar::Script_Javanese85 
QChar::Script_Kaithi92 
QChar::Script_Kannada18 
QChar::Script_Katakana35 
QChar::Script_Kawi (since Qt 6.5)162 
QChar::Script_KayahLi72 
QChar::Script_Kharoshthi61 
QChar::Script_KhitanSmallScript (since Qt 5.15)155 
QChar::Script_Khmer32 
QChar::Script_Khojki (since Qt 5.5)109 
QChar::Script_Khudawadi (since Qt 5.5)123 
QChar::Script_Lao22 
QChar::Script_Latin3 
QChar::Script_Lepcha68 
QChar::Script_Limbu47 
QChar::Script_LinearA (since Qt 5.5)110 
QChar::Script_LinearB49 
QChar::Script_Lisu83 
QChar::Script_Lycian74 
QChar::Script_Lydian76 
QChar::Script_Mahajani (since Qt 5.5)111 
QChar::Script_Makasar (since Qt 5.15)145 
QChar::Script_Malayalam19 
QChar::Script_Mandaic95 
QChar::Script_Manichaean (since Qt 5.5)112 
QChar::Script_Marchen (since Qt 5.11)134 
QChar::Script_MasaramGondi (since Qt 5.11)138 
QChar::Script_Medefaidrin (since Qt 5.15)146 
QChar::Script_MeeteiMayek86 
QChar::Script_MendeKikakui (since Qt 5.5)113 
QChar::Script_MeroiticCursive97 
QChar::Script_MeroiticHieroglyphs98 
QChar::Script_Miao99 
QChar::Script_Modi (since Qt 5.5)114 
QChar::Script_Mongolian33 
QChar::Script_Mro (since Qt 5.5)115 
QChar::Script_Multani (since Qt 5.6)129 
QChar::Script_Myanmar24 
QChar::Script_Nabataean (since Qt 5.5)117 
QChar::Script_NagMundari (since Qt 6.3)163 
QChar::Script_Nandinagari (since Qt 5.15)150 
QChar::Script_Newa (since Qt 5.11)135 
QChar::Script_NewTaiLue56 
QChar::Script_Nko66 
QChar::Script_Nushu (since Qt 5.11)139 
QChar::Script_NyiakengPuachueHmong (since Qt 5.15)151 
QChar::Script_Ogham30 
QChar::Script_OlChiki69 
QChar::Script_OldHungarian (since Qt 5.6)130 
QChar::Script_OldItalic39 
QChar::Script_OldNorthArabian (since Qt 5.5)116 
QChar::Script_OldPermic (since Qt 5.5)120 
QChar::Script_OldPersian60 
QChar::Script_OldSogdian (since Qt 5.15)147 
QChar::Script_OldSouthArabian88 
QChar::Script_OldTurkic91 
QChar::Script_OldUyghur (since Qt 6.3)158 
QChar::Script_Oriya15 
QChar::Script_Osage (since Qt 5.11)136 
QChar::Script_Osmanya52 
QChar::Script_PahawhHmong (since Qt 5.5)108 
QChar::Script_Palmyrene (since Qt 5.5)118 
QChar::Script_PauCinHau (since Qt 5.5)119 
QChar::Script_PhagsPa65 
QChar::Script_Phoenician64 
QChar::Script_PsalterPahlavi (since Qt 5.5)121 
QChar::Script_Rejang73 
QChar::Script_Runic31 
QChar::Script_Samaritan82 
QChar::Script_Saurashtra71 
QChar::Script_Sharada100 
QChar::Script_Shavian51 
QChar::Script_Siddham (since Qt 5.5)122 
QChar::Script_SignWriting (since Qt 5.6)131 
QChar::Script_Sinhala20 
QChar::Script_Sogdian (since Qt 5.15)148 
QChar::Script_SoraSompeng101 
QChar::Script_Soyombo (since Qt 5.11)140 
QChar::Script_Sundanese67 
QChar::Script_SylotiNagri59 
QChar::Script_Syriac9 
QChar::Script_Tagalog42 
QChar::Script_Tagbanwa45 
QChar::Script_TaiLe48 
QChar::Script_TaiTham78 
QChar::Script_TaiViet79 
QChar::Script_Takri102 
QChar::Script_Tamil16 
QChar::Script_Tangut (since Qt 5.11)137 
QChar::Script_Tangsa (since Qt 6.3)159 
QChar::Script_Telugu17 
QChar::Script_Thaana10 
QChar::Script_Thai21 
QChar::Script_Tibetan23 
QChar::Script_Tifinagh58 
QChar::Script_Tirhuta (since Qt 5.5)124 
QChar::Script_Toto (since Qt 6.3)160 
QChar::Script_Ugaritic50 
QChar::Script_Vai70 
QChar::Script_Vithkuqi (since Qt 6.3)161 
QChar::Script_Wancho (since Qt 5.15)152 
QChar::Script_WarangCiti (since Qt 5.5)125 
QChar::Script_Yezidi (since Qt 5.15)156 
QChar::Script_Yi38 
QChar::Script_ZanabazarSquare (since Qt 5.11)141 

See also script().

enum QChar::SpecialCharacter

ConstantValueDescription
QChar::Null0x0000A QChar with this value isNull().
QChar::Tabulation0x0009Character tabulation.
QChar::LineFeed0x000a 
QChar::FormFeed0x000c 
QChar::CarriageReturn0x000d 
QChar::Space0x0020 
QChar::Nbsp0x00a0Non-breaking space.
QChar::SoftHyphen0x00ad 
QChar::ReplacementCharacter0xfffdThe character shown when a font has no glyph for a certain codepoint. A special question mark character is often used. Codecs use this codepoint when input data cannot be represented in Unicode.
QChar::ObjectReplacementCharacter0xfffcUsed to represent an object such as an image when such objects cannot be presented.
QChar::ByteOrderMark0xfeff 
QChar::ByteOrderSwapped0xfffe 
QChar::ParagraphSeparator0x2029 
QChar::LineSeparator0x2028 
QChar::VisualTabCharacter (since Qt 6.2)0x2192Used to represent a tabulation as a horizontal arrow.
QChar::LastValidCodePoint0x10ffff 

enum QChar::UnicodeVersion

Specifies which version of the Unicode standard introduced a certain character.

ConstantValueDescription
QChar::Unicode_1_11Version 1.1
QChar::Unicode_2_02Version 2.0
QChar::Unicode_2_1_23Version 2.1.2
QChar::Unicode_3_04Version 3.0
QChar::Unicode_3_15Version 3.1
QChar::Unicode_3_26Version 3.2
QChar::Unicode_4_07Version 4.0
QChar::Unicode_4_18Version 4.1
QChar::Unicode_5_09Version 5.0
QChar::Unicode_5_110Version 5.1
QChar::Unicode_5_211Version 5.2
QChar::Unicode_6_012Version 6.0
QChar::Unicode_6_113Version 6.1
QChar::Unicode_6_214Version 6.2
QChar::Unicode_6_3 (since Qt 5.3)15Version 6.3
QChar::Unicode_7_0 (since Qt 5.5)16Version 7.0
QChar::Unicode_8_0 (since Qt 5.6)17Version 8.0
QChar::Unicode_9_0 (since Qt 5.11)18Version 9.0
QChar::Unicode_10_0 (since Qt 5.11)19Version 10.0
QChar::Unicode_11_0 (since Qt 5.15)20Version 11.0
QChar::Unicode_12_0 (since Qt 5.15)21Version 12.0
QChar::Unicode_12_1 (since Qt 5.15)22Version 12.1
QChar::Unicode_13_0 (since Qt 5.15)23Version 13.0
QChar::Unicode_14_0 (since Qt 6.3)24Version 14.0
QChar::Unicode_15_0 (since Qt 6.5)25Version 15.0
QChar::Unicode_Unassigned0The value is not assigned to any character in version 8.0 of Unicode.

See also unicodeVersion() and currentUnicodeVersion().

Member Function Documentation

[constexpr] QChar::QChar()

Constructs a null QChar ('\0').

See also isNull().

[constexpr] QChar::QChar(ushort code)

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

[constexpr] QChar::QChar(uchar cell, uchar row)

Constructs a QChar for Unicode cell cell in row row.

See also cell() and row().

[constexpr] QChar::QChar(short code)

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

[constexpr] QChar::QChar(uint code)

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

[constexpr] QChar::QChar(int code)

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

[constexpr] QChar::QChar(QChar::SpecialCharacter ch)

Constructs a QChar for the predefined character value ch.

[constexpr] QChar::QChar(QLatin1Char ch)

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

[constexpr] QChar::QChar(char16_t ch)

Constructs a QChar corresponding to the UTF-16 character ch.

[constexpr] QChar::QChar(wchar_t ch)

Constructs a QChar corresponding to the wide character ch.

Note: This constructor is only available on Windows.

[constexpr] QChar::QChar(char ch)

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

Note: This constructor is not available when QT_NO_CAST_FROM_ASCII is defined.

See also QT_NO_CAST_FROM_ASCII.

[constexpr] QChar::QChar(uchar ch)

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

Note: This constructor is not available when QT_NO_CAST_FROM_ASCII or QT_RESTRICTED_CAST_FROM_ASCII is defined.

See also QT_NO_CAST_FROM_ASCII and QT_RESTRICTED_CAST_FROM_ASCII.

QChar::Category QChar::category() const

Returns the character's category.

[static] QChar::Category QChar::category(char32_t ucs4)

This is an overloaded function.

Returns the category of the UCS-4-encoded character specified by ucs4.

Note: Before Qt 6, this function took a uint argument.

[constexpr] 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.

[static] unsigned char QChar::combiningClass(char32_t ucs4)

This is an overloaded function.

Returns the combining class for the UCS-4-encoded character specified by ucs4, as defined in the Unicode standard.

Note: Before Qt 6, this function took a uint argument.

[static] QChar::UnicodeVersion QChar::currentUnicodeVersion()

Returns the most recent supported Unicode version.

QString QChar::decomposition() const

Decomposes a character into it's constituent parts. Returns an empty string if no decomposition exists.

[static] QString QChar::decomposition(char32_t ucs4)

This is an overloaded function.

Decomposes the UCS-4-encoded character specified by ucs4 into it's constituent parts. Returns an empty string if no decomposition exists.

Note: Before Qt 6, this function took a uint argument.

QChar::Decomposition QChar::decompositionTag() const

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

[static] QChar::Decomposition QChar::decompositionTag(char32_t ucs4)

This is an overloaded function.

Returns the tag defining the composition of the UCS-4-encoded character specified by ucs4. Returns QChar::NoDecomposition if no decomposition exists.

Note: Before Qt 6, this function took a uint argument.

int QChar::digitValue() const

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

[static] int QChar::digitValue(char32_t ucs4)

This is an overloaded function.

Returns the numeric value of the digit specified by the UCS-4-encoded character, ucs4, or -1 if the character is not a digit.

Note: Before Qt 6, this function took a uint argument.

QChar::Direction QChar::direction() const

Returns the character's direction.

[static] QChar::Direction QChar::direction(char32_t ucs4)

This is an overloaded function.

Returns the direction of the UCS-4-encoded character specified by ucs4.

Note: Before Qt 6, this function took a uint argument.

[static constexpr] QChar QChar::fromLatin1(char c)

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

An alternative is to use QLatin1Char.

See also toLatin1() and unicode().

[static constexpr, since 6.0] QChar QChar::fromUcs2(char16_t c)

Constructs a QChar from UTF-16 character c.

This function was introduced in Qt 6.0.

See also fromUcs4().

[static constexpr, since 6.0] R QChar::fromUcs4(char32_t c)

Returns an anonymous struct that

  • contains a char16_t chars[2] array,
  • can be implicitly converted to a QStringView, and
  • iterated over with a C++11 ranged for loop.

If c requires surrogates, chars[0] contains the high surrogate and chars[1] the low surrogate, and the QStringView has size 2. Otherwise, chars[0] contains c and chars[1] is null, and the QStringView has size 1.

This allows easy use of the result:

QString s;
s += QChar::fromUcs4(ch);
for (char16_t c16 : QChar::fromUcs4(ch))
    use(c16);

This function was introduced in Qt 6.0.

See also fromUcs2() and requiresSurrogates().

bool QChar::hasMirrored() const

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

A bit faster equivalent of (ch.mirroredChar() != ch).

See also mirroredChar().

[static] bool QChar::hasMirrored(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 should be reversed if the text direction is reversed; otherwise returns false.

A bit faster equivalent of (QChar::mirroredChar(ucs4) != ucs4).

Note: Before Qt 6, this function took a uint argument.

See also mirroredChar().

[static constexpr] char16_t QChar::highSurrogate(char32_t ucs4)

Returns the high surrogate part of a UCS-4-encoded code point. The returned result is undefined if ucs4 is smaller than 0x10000.

Note: Before Qt 6, this function took a uint argument and returned ushort.

[constexpr] bool QChar::isDigit() const

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

See also isNumber().

[static constexpr] bool QChar::isDigit(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is a decimal digit (Number_DecimalDigit); otherwise returns false.

Note: Before Qt 6, this function took a uint argument.

See also isNumber().

[constexpr] bool QChar::isHighSurrogate() const

Returns true if the QChar is the high part of a UTF16 surrogate (for example if its code point is in range [0xd800..0xdbff]); false otherwise.

[static constexpr] bool QChar::isHighSurrogate(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is the high part of a UTF16 surrogate (for example if its code point is in range [0xd800..0xdbff]); false otherwise.

Note: Before Qt 6, this function took a uint argument.

[constexpr] bool QChar::isLetter() const

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

[static constexpr] bool QChar::isLetter(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is a letter (Letter_* categories); otherwise returns false.

Note: Before Qt 6, this function took a uint argument.

[constexpr] bool QChar::isLetterOrNumber() const

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

[static constexpr] bool QChar::isLetterOrNumber(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is a letter or number (Letter_* or Number_* categories); otherwise returns false.

Note: Before Qt 6, this function took a uint argument.

[constexpr] bool QChar::isLowSurrogate() const

Returns true if the QChar is the low part of a UTF16 surrogate (for example if its code point is in range [0xdc00..0xdfff]); false otherwise.

[static constexpr] bool QChar::isLowSurrogate(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is the low part of a UTF16 surrogate (for example if its code point is in range [0xdc00..0xdfff]); false otherwise.

Note: Before Qt 6, this function took a uint argument.

[constexpr] bool QChar::isLower() const

Returns true if the character is a lowercase letter, for example category() is Letter_Lowercase.

See also isUpper(), toLower(), and toUpper().

[static constexpr] bool QChar::isLower(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is a lowercase letter, for example category() is Letter_Lowercase.

Note: Before Qt 6, this function took a uint argument.

See also isUpper(), toLower(), and toUpper().

bool QChar::isMark() const

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

See QChar::Category for more information regarding marks.

[static] bool QChar::isMark(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is a mark (Mark_* categories); otherwise returns false.

Note: Before Qt 6, this function took a uint argument.

[constexpr] bool QChar::isNonCharacter() const

Returns true if the QChar is a non-character; false otherwise.

Unicode has a certain number of code points that are classified as "non-characters:" that is, they can be used for internal purposes in applications but cannot be used for text interchange. Those are the last two entries each Unicode Plane ([0xfffe..0xffff], [0x1fffe..0x1ffff], etc.) as well as the entries in range [0xfdd0..0xfdef].

[static constexpr] bool QChar::isNonCharacter(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is a non-character; false otherwise.

Unicode has a certain number of code points that are classified as "non-characters:" that is, they can be used for internal purposes in applications but cannot be used for text interchange. Those are the last two entries each Unicode Plane ([0xfffe..0xffff], [0x1fffe..0x1ffff], etc.) as well as the entries in range [0xfdd0..0xfdef].

Note: Before Qt 6, this function took a uint argument.

[constexpr] bool QChar::isNull() const

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

[constexpr] bool QChar::isNumber() const

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

See also isDigit().

[static constexpr] bool QChar::isNumber(char32_t ucs4)

This is an overloaded function.

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

Note: Before Qt 6, this function took a uint argument.

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 Other_*.

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

[static] bool QChar::isPrint(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is a printable character; otherwise returns false. This is any character not of category Other_*.

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

Note: Before Qt 6, this function took a uint argument.

bool QChar::isPunct() const

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

[static] bool QChar::isPunct(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is a punctuation mark (Punctuation_* categories); otherwise returns false.

Note: Before Qt 6, this function took a uint argument.

[constexpr] bool QChar::isSpace() const

Returns true if the character is a separator character (Separator_* categories or certain code points from Other_Control category); otherwise returns false.

[static constexpr] bool QChar::isSpace(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is a separator character (Separator_* categories or certain code points from Other_Control category); otherwise returns false.

Note: Before Qt 6, this function took a uint argument.

[constexpr] bool QChar::isSurrogate() const

Returns true if the QChar contains a code point that is in either the high or the low part of the UTF-16 surrogate range (for example if its code point is in range [0xd800..0xdfff]); false otherwise.

[static constexpr] bool QChar::isSurrogate(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 contains a code point that is in either the high or the low part of the UTF-16 surrogate range (for example if its code point is in range [0xd800..0xdfff]); false otherwise.

Note: Before Qt 6, this function took a uint argument.

bool QChar::isSymbol() const

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

[static] bool QChar::isSymbol(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is a symbol (Symbol_* categories); otherwise returns false.

Note: Before Qt 6, this function took a uint argument.

[constexpr] bool QChar::isTitleCase() const

Returns true if the character is a titlecase letter, for example category() is Letter_Titlecase.

See also isLower(), toUpper(), toLower(), and toTitleCase().

[static constexpr] bool QChar::isTitleCase(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is a titlecase letter, for example category() is Letter_Titlecase.

Note: Before Qt 6, this function took a uint argument.

See also isLower(), toUpper(), toLower(), and toTitleCase().

[constexpr] bool QChar::isUpper() const

Returns true if the character is an uppercase letter, for example category() is Letter_Uppercase.

See also isLower(), toUpper(), and toLower().

[static constexpr] bool QChar::isUpper(char32_t ucs4)

This is an overloaded function.

Returns true if the UCS-4-encoded character specified by ucs4 is an uppercase letter, for example category() is Letter_Uppercase.

Note: Before Qt 6, this function took a uint argument.

See also isLower(), toUpper(), and toLower().

QChar::JoiningType QChar::joiningType() const

Returns information about the joining type attributes of the character (needed for certain languages such as Arabic or Syriac).

[static] QChar::JoiningType QChar::joiningType(char32_t ucs4)

This is an overloaded function.

Returns information about the joining type attributes of the UCS-4-encoded character specified by ucs4 (needed for certain languages such as Arabic or Syriac).

Note: Before Qt 6, this function took a uint argument.

[static constexpr] char16_t QChar::lowSurrogate(char32_t ucs4)

Returns the low surrogate part of a UCS-4-encoded code point. The returned result is undefined if ucs4 is smaller than 0x10000.

Note: Before Qt 6, this function took a uint argument and returned ushort.

QChar QChar::mirroredChar() const

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

See also hasMirrored().

[static] char32_t QChar::mirroredChar(char32_t ucs4)

This is an overloaded function.

Returns the mirrored character if the UCS-4-encoded character specified by ucs4 is a mirrored character; otherwise returns the character itself.

Note: Before Qt 6, this function took a uint argument and returned uint.

See also hasMirrored().

[static constexpr] bool QChar::requiresSurrogates(char32_t ucs4)

Returns true if the UCS-4-encoded character specified by ucs4 can be split into the high and low parts of a UTF16 surrogate (for example if its code point is greater than or equals to 0x10000); false otherwise.

Note: Before Qt 6, this function took a uint argument.

[constexpr] uchar QChar::row() const

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

See also cell().

QChar::Script QChar::script() const

Returns the Unicode script property value for this character.

[static] QChar::Script QChar::script(char32_t ucs4)

This is an overloaded function.

Returns the Unicode script property value for the character specified in its UCS-4-encoded form as ucs4.

Note: Before Qt 6, this function took a uint argument.

[static constexpr] char32_t QChar::surrogateToUcs4(char16_t high, char16_t low)

Converts a UTF16 surrogate pair with the given high and low values to it's UCS-4-encoded code point.

Note: Before Qt 6, this function took ushort arguments and returned uint.

[static constexpr] char32_t QChar::surrogateToUcs4(QChar high, QChar low)

This is an overloaded function.

Converts a UTF16 surrogate pair (high, low) to it's UCS-4-encoded code point.

Note: Before Qt 6, this function returned uint.

QChar QChar::toCaseFolded() const

Returns the case folded equivalent of the character. For most Unicode characters this is the same as toLower().

[static] char32_t QChar::toCaseFolded(char32_t ucs4)

This is an overloaded function.

Returns the case folded equivalent of the UCS-4-encoded character specified by ucs4. For most Unicode characters this is the same as toLower().

Note: Before Qt 6, this function took a uint argument and returned uint.

[constexpr] char QChar::toLatin1() const

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

Note: It is not possible to distinguish a non-Latin-1 character from a Latin-1 0 (NUL) character. Prefer to use unicode(), which does not have this ambiguity.

See also unicode().

QChar QChar::toLower() const

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

[static] char32_t QChar::toLower(char32_t ucs4)

This is an overloaded function.

Returns the lowercase equivalent of the UCS-4-encoded character specified by ucs4 if the character is uppercase or titlecase; otherwise returns the character itself.

Note: Before Qt 6, this function took a uint argument and returned uint.

QChar QChar::toTitleCase() const

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

[static] char32_t QChar::toTitleCase(char32_t ucs4)

This is an overloaded function.

Returns the title case equivalent of the UCS-4-encoded character specified by ucs4 if the character is lowercase or uppercase; otherwise returns the character itself.

Note: Before Qt 6, this function took a uint argument and returned uint.

QChar QChar::toUpper() const

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

Note: This function also returns the original character in the rare case of the uppercase form of the character requiring two or more characters.

See also QString::toUpper().

[static] char32_t QChar::toUpper(char32_t ucs4)

This is an overloaded function.

Returns the uppercase equivalent of the UCS-4-encoded character specified by ucs4 if the character is lowercase or titlecase; otherwise returns the character itself.

Note: This function also returns the original character in the rare case of the uppercase form of the character requiring two or more characters.

Note: Before Qt 6, this function took a uint argument and returned uint.

See also QString::toUpper().

[constexpr] char16_t QChar::unicode() const

Returns the numeric Unicode value of the QChar.

[constexpr] char16_t &QChar::unicode()

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

QChar::UnicodeVersion QChar::unicodeVersion() const

Returns the Unicode version that introduced this character.

[static] QChar::UnicodeVersion QChar::unicodeVersion(char32_t ucs4)

This is an overloaded function.

Returns the Unicode version that introduced the character specified in its UCS-4-encoded form as ucs4.

Note: Before Qt 6, this function took a uint argument.

Related Non-Members

[constexpr] bool operator!=(QChar c1, QChar c2)

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

[constexpr] bool operator<(QChar c1, QChar c2)

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

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

Writes the char chr to the stream out.

See also Serializing Qt Data Types.

[constexpr] bool operator<=(QChar c1, QChar c2)

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

[constexpr] bool operator==(QChar c1, QChar c2)

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

[constexpr] bool operator>(QChar c1, QChar c2)

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

[constexpr] bool operator>=(QChar c1, QChar c2)

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)

Reads a char from the stream in into char chr.

See also Serializing Qt Data Types.

Macro Documentation

[since 6.0] QT_IMPLICIT_QCHAR_CONSTRUCTION

Defining this macro makes certain QChar constructors implicit rather than explicit. This is done to enforce safe conversions:

QString str = getString();
if (str == 123) {
    // Oops, meant str == "123". By default does not compile,
    // *unless* this macro is defined, in which case, it's interpreted
    // as `if (str == QChar(123))`, that is, `if (str == '{')`.
    // Likely, not what we meant.
}

This macro is provided to keep existing code working; it is recommended to instead use explicit conversions and/or QLatin1Char. For instance:

QChar c1 =  'x'; // OK, unless QT_NO_CAST_FROM_ASCII is defined
QChar c2 = u'x'; // always OK, recommended
QChar c3 = QLatin1Char('x'); // always OK, recommended

// from int to 1 UTF-16 code unit: must guarantee that the input is <= 0xFFFF
QChar c4 = 120;        // compile error, unless QT_IMPLICIT_QCHAR_CONSTRUCTION is defined
QChar c5(120);         // OK (direct initialization)
auto  c6 = QChar(120); // ditto

// from int/char32_t to 1/2 UTF-16 code units:
// 𝄞 'MUSICAL SYMBOL G CLEF' (U+1D11E)
auto c7 = QChar(0x1D11E);           // compiles, but undefined behavior at runtime
auto c8 = QChar::fromUcs4(0x1D11E);       // always OK
auto c9 = QChar::fromUcs4(U'\U0001D11E'); // always OK
// => use c8/c9 as QStringView objects

This macro was introduced in Qt 6.0.

See also QLatin1Char, QChar::fromUcs4, and QT_NO_CAST_FROM_ASCII.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.