QString Class
The QString class provides a Unicode character string. More…
| Header | #include <QString> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Types
| enum | NormalizationForm |
| typedef | iterator |
| typedef | const_iterator |
| typedef | reverse_iterator |
| typedef | const_reverse_iterator |
| typedef | value_type |
| typedef | size_type |
Public Functions
| QString() | |
| QString(const char *utf8) | |
| QString(const char16_t *u, qsizetype size = -1) | |
| QString(const QChar *u, qsizetype size) | |
| QString(QChar c) | |
| QString(qsizetype size, QChar c) | |
| QString(qsizetype size, Qt::Initialization) | |
| QString(QLatin1StringView s) | |
| QString(const QByteArray &utf8) | |
| QString(const std::u16string &s) | |
| qsizetype | size() const |
| qsizetype | length() const |
| qsizetype | count() const |
| qsizetype | capacity() const |
| bool | isEmpty() const |
| bool | isNull() const |
| void | clear() |
| void | reserve(qsizetype n) |
| void | squeeze() |
| void | resize(qsizetype n) |
| void | resize(qsizetype n, QChar c) |
| void | resizeForOverwrite(qsizetype size) |
| QString & | fill(QChar c, qsizetype n = -1) |
| void | truncate(qsizetype pos) |
| void | chop(qsizetype n) |
| QChar | at(qsizetype i) const |
| QChar | operator[](qsizetype i) const |
| QChar & | operator[](qsizetype i) |
| QChar | front() const |
| QChar | back() const |
| QChar * | data() |
| const QChar * | data() const |
| const QChar * | constData() const |
| const char16_t * | utf16() const |
| const std::u16string & | u16string() const |
| iterator | begin() |
| iterator | end() |
| const_iterator | begin() const |
| const_iterator | end() const |
| const_iterator | cbegin() const |
| const_iterator | cend() const |
| const_iterator | constBegin() const |
| const_iterator | constEnd() const |
| QString & | append(const QString &s) |
| QString & | append(QChar c) |
| QString & | append(QLatin1StringView s) |
| QString & | append(const char *s) |
| void | push_back(QChar c) |
| void | push_back(const QString &s) |
| QString & | prepend(const QString &s) |
| QString & | prepend(QChar c) |
| QString & | insert(qsizetype pos, const QString &s) |
| QString & | insert(qsizetype pos, QChar c) |
| QString & | remove(qsizetype pos, qsizetype len) |
| QString & | remove(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| QString & | remove(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| QString & | replace(qsizetype pos, qsizetype len, const QString &after) |
| QString & | replace(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| QString & | replace(QChar before, QChar after, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| QString & | replace(QChar before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| QString & | operator+=(const QString &s) |
| QString & | operator+=(QChar c) |
| QString & | operator+=(const char *s) |
| QString | mid(qsizetype pos, qsizetype len = -1) const |
| QString | left(qsizetype n) const |
| QString | right(qsizetype n) const |
| QString | first(qsizetype n) const |
| QString | last(qsizetype n) const |
| QString | sliced(qsizetype pos, qsizetype n) const |
| QString | sliced(qsizetype pos) const |
| QString | chopped(qsizetype n) const |
| QString | trimmed() const |
| QString | simplified() const |
| QString | toUpper() const |
| QString | toLower() const |
| QString | toCaseFolded() const |
| QString | repeated(qsizetype times) const |
| QString | leftJustified(qsizetype width, QChar fill = QChar(u' '), bool truncate = false) const |
| QString | rightJustified(qsizetype width, QChar fill = QChar(u' '), bool truncate = false) const |
| QString | section(QChar sep, qsizetype start, qsizetype end = -1) const |
| QString | section(const QString &sep, qsizetype start, qsizetype end = -1) const |
| bool | startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | indexOf(const QString &s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | lastIndexOf(const QString &s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | lastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QStringList | split(const QString &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QStringList | split(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| auto | tokenize(Needle &&needle, Flags... flags) const & |
| auto | tokenize(Needle &&needle, Flags... flags) && |
| bool | contains(const QRegularExpression &re, QRegularExpressionMatch *rmatch = nullptr) const |
| qsizetype | indexOf(const QRegularExpression &re, qsizetype from = 0, QRegularExpressionMatch *rmatch = nullptr) const |
| qsizetype | lastIndexOf(const QRegularExpression &re, QRegularExpressionMatch *rmatch = nullptr) const |
| qsizetype | lastIndexOf(const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch = nullptr) const |
| qsizetype | count(const QRegularExpression &re) const |
| QString & | replace(const QRegularExpression &re, const QString &after) |
| QString & | remove(const QRegularExpression &re) |
| QStringList | split(const QRegularExpression &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const |
| QString | arg(const QString &a, int fieldWidth = 0, QChar fillChar = QChar(u' ')) const |
| QString | arg(QChar a, int fieldWidth = 0, QChar fillChar = QChar(u' ')) const |
| QString | arg(char a, int fieldWidth = 0, QChar fillChar = QChar(u' ')) const |
| QString | arg(const char *a, int fieldWidth = 0, QChar fillChar = QChar(u' ')) const |
| QString | arg(qlonglong a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const |
| QString | arg(qulonglong a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const |
| QString | arg(long a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const |
| QString | arg(ulong a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const |
| QString | arg(int a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const |
| QString | arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const |
| QString | arg(short a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const |
| QString | arg(ushort a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const |
| QString | arg(double a, int fieldWidth = 0, char format = 'g', int precision = -1, QChar fillChar = QChar(u' ')) const |
| QString | arg(const A1 &a1, const A2 &a2, const Rest &...rest) const |
| QString & | setNum(qlonglong n, int base = 10) |
| QString & | setNum(qulonglong n, int base = 10) |
| QString & | setNum(int n, int base = 10) |
| QString & | setNum(uint n, int base = 10) |
| QString & | setNum(double n, char format = 'g', int precision = 6) |
| int | toInt(bool *ok = nullptr, int base = 10) const |
| uint | toUInt(bool *ok = nullptr, int base = 10) const |
| long | toLong(bool *ok = nullptr, int base = 10) const |
| ulong | toULong(bool *ok = nullptr, int base = 10) const |
| qlonglong | toLongLong(bool *ok = nullptr, int base = 10) const |
| qulonglong | toULongLong(bool *ok = nullptr, int base = 10) const |
| short | toShort(bool *ok = nullptr, int base = 10) const |
| ushort | toUShort(bool *ok = nullptr, int base = 10) const |
| double | toDouble(bool *ok = nullptr) const |
| float | toFloat(bool *ok = nullptr) const |
| QByteArray | toUtf8() const |
| QByteArray | toLatin1() const |
| QByteArray | toLocal8Bit() const |
| std::string | toStdString() const |
| std::u16string | toStdU16String() const |
| std::u32string | toStdU32String() const |
| std::wstring | toStdWString() const |
| QList<uint> | toUcs4() const |
| qsizetype | toWCharArray(wchar_t *array) const |
| QString | normalized(NormalizationForm mode) const |
| QString | toHtmlEscaped() const |
| bool | isValidUtf16() const |
| bool | isUpper() const |
| bool | isLower() const |
| const QChar * | unicode() const |
| QString & | setUnicode(const QChar *unicode, qsizetype size) |
| QString & | setUtf16(const char16_t *utf16, qsizetype size) |
| QString & | setRawData(const QChar *unicode, qsizetype size) |
| QString & | slice(qsizetype pos) |
| QString & | slice(qsizetype pos, qsizetype n) |
| QString & | nullTerminate() |
| QString | nullTerminated() const |
| QString & | removeIf(Predicate pred) |
| QString & | removeAt(qsizetype pos) |
| QString & | removeFirst() |
| QString & | removeLast() |
| iterator | erase(const_iterator first, const_iterator last) |
| iterator | erase(const_iterator it) |
| void | push_front(QChar c) |
| void | push_front(const QString &s) |
| void | shrink_to_fit() |
| qsizetype | max_size() const |
| reverse_iterator | rbegin() |
| const_reverse_iterator | rbegin() const |
| reverse_iterator | rend() |
| const_reverse_iterator | rend() const |
| const_reverse_iterator | crbegin() const |
| const_reverse_iterator | crend() const |
| QString & | assign(const QAnyStringView &v) |
| QString & | assign(qsizetype n, QChar c) |
| QString & | assign(InputIterator first, InputIterator last) |
| int | compare(const QString &o, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | isRightToLeft() const |
| void | swap(QString &o) |
Static Public Members
| QString | number(qlonglong n, int base = 10) |
| QString | number(qulonglong n, int base = 10) |
| QString | number(int n, int base = 10) |
| QString | number(uint n, int base = 10) |
| QString | number(long n, int base = 10) |
| QString | number(ulong n, int base = 10) |
| QString | number(double n, char format = 'g', int precision = 6) |
| QString | fromUtf8(const char *s, qsizetype size = -1) |
| QString | fromUtf8(const QByteArray &b) |
| QString | fromLatin1(const char *s, qsizetype size = -1) |
| QString | fromLatin1(const QByteArray &b) |
| QString | fromLatin1(QByteArrayView b) |
| QString | fromLocal8Bit(const char *s, qsizetype size = -1) |
| QString | fromLocal8Bit(const QByteArray &b) |
| QString | fromStdString(const std::string &s) |
| QString | fromStdU16String(const std::u16string &s) |
| QString | fromUtf16(const char16_t *s, qsizetype size = -1) |
| QString | fromRawData(const QChar *u, qsizetype size) |
| QString | fromStdU32String(const std::u32string &s) |
| QString | fromStdWString(const std::wstring &s) |
| QString | fromUcs4(const char32_t *unicode, qsizetype size = -1) |
| QString | fromWCharArray(const wchar_t *string, qsizetype size = -1) |
| qsizetype | maxSize() |
| QString | vasprintf(const char *fmt, va_list ap) |
| int | compare(const QString &a, const QString &b, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| int | localeAwareCompare(const QString &a, const QString &b) |
| QString | asprintf(const char *fmt, ...) |
Detailed Description
QString stores a string of 16-bit QChars (UTF-16 code units). It is the string type used throughout Nt. Strings are created from UTF-8 literals, Latin-1 data or UTF-16 data, and converted back with toUtf8(), toLatin1() and toStdString():
QString s = QStringLiteral("Hello, %1!").arg("world");
if (s.startsWith("Hello"))
qDebug() << s.toUpper();
A QString can be null (the result of the default constructor, see isNull()) or empty (no characters); a null string is also empty, and the two are interchangeable in comparisons.
Unlike in Qt the string data is not implicitly shared: every copy of a QString copies the characters.
See also QChar, QStringList, QStringView and QByteArray.
Differences from Qt
The string is a thin wrapper around std::u16string and copies on assignment; there is no implicit sharing, so fromRawData() copies its argument. Case-insensitive comparison and searching use the simple case folding of each character, so "ß" does not match "ss". localeAwareCompare() uses QCollator, whose collation is simplified; toLocal8Bit() and fromLocal8Bit() use UTF-8. count() returns 0 for an empty argument. Functions taking QStringView or QLatin1StringView are mostly missing; use the QString overloads. section() has no QRegularExpression overload. setRawData() copies the data. There is no QStringBuilder concatenation.
Member Type Documentation
typedef QString::const_iterator
A read-only random-access iterator over the characters of the string. It is a plain const QChar *.
typedef QString::const_reverse_iterator
The const reverse iterator type, for STL compatibility.
typedef QString::iterator
A mutable random-access iterator over the characters of the string. It is a plain QChar *.
enum QString::NormalizationForm
The Unicode normalization forms. The enum is declared for source compatibility; Nt provides no normalized() function.
| Constant | Description |
|---|---|
QString::NormalizationForm_D | Canonical decomposition. |
QString::NormalizationForm_C | Canonical decomposition followed by canonical composition. |
QString::NormalizationForm_KD | Compatibility decomposition. |
QString::NormalizationForm_KC | Compatibility decomposition followed by canonical composition. |
typedef QString::reverse_iterator
The reverse iterator type, for STL compatibility.
typedef QString::size_type
The type used for sizes and indexes, for STL compatibility.
typedef QString::value_type
The element type of the string, for STL compatibility.
Member Function Documentation
QString::QString()
Constructs a null string.
See also isNull().
QString::QString(const char *utf8)
Constructs a string from the null-terminated UTF-8 string utf8. Invalid sequences are replaced by U+FFFD. If utf8 is nullptr the string is null.
See also fromUtf8().
QString::QString(const char16_t *u, qsizetype size = -1)
This is an overloaded function.
Constructs a string from the first size UTF-16 code units of u. If size is negative, u must be null-terminated. If u is nullptr the string is null.
See also fromUtf16().
QString::QString(const QChar *u, qsizetype size)
This is an overloaded function.
Constructs a string from the first size characters of u. If u is nullptr the string is null.
QString::QString(QChar c)
This is an overloaded function.
Constructs a string of size 1 containing the character c.
QString::QString(qsizetype size, QChar c)
This is an overloaded function.
Constructs a string of the given size with every character set to c. A negative size gives an empty, non-null string.
QString::QString(qsizetype size, Qt::Initialization)
This is an overloaded function.
Constructs a string of the given size whose characters the caller is about to assign. Pass Qt::Uninitialized as the second argument; Nt sets the characters to U+0000.
QString::QString(QLatin1StringView s)
This is an overloaded function.
Constructs a string from the Latin-1 string s. The result is not null, even if s is empty.
See also fromLatin1().
QString::QString(const QByteArray &utf8)
This is an overloaded function.
Constructs a string from the UTF-8 data in utf8. The string is null if utf8 is null.
See also fromUtf8().
QString::QString(const std::u16string &s)
This is an overloaded function.
Constructs a string holding a copy of the UTF-16 string s. The result is never null.
See also fromStdU16String() and toStdU16String().
QString & QString::append(const QString &s)
Appends the string s to this string and returns a reference to it.
See also prepend() and insert().
QString & QString::append(QChar c)
This is an overloaded function.
Appends the character c to this string.
QString & QString::append(QLatin1StringView s)
This is an overloaded function.
Appends the Latin-1 string s to this string.
QString & QString::append(const char *s)
This is an overloaded function.
Appends the UTF-8 encoded string s to this string.
QString QString::arg(const QString &a, int fieldWidth = 0, QChar fillChar = QChar(u' ')) const
Returns a copy of this string in which the lowest-numbered place marker (%1 to %99, optionally written %L1) is replaced by a.
a is padded to at least fieldWidth characters with fillChar; a positive fieldWidth right-aligns it and a negative one left-aligns it (padding with spaces). If the string contains no place marker, a space and a are appended.
QString s = QString("%1 of %2").arg("1").arg("3"); // "1 of 3"
See also number().
QString QString::arg(QChar a, int fieldWidth = 0, QChar fillChar = QChar(u' ')) const
This is an overloaded function.
Replaces the lowest-numbered %n place marker with the character a, padded to fieldWidth with fillChar.
QString QString::arg(char a, int fieldWidth = 0, QChar fillChar = QChar(u' ')) const
This is an overloaded function.
Replaces the lowest-numbered %n place marker with the character a, interpreted as Latin-1 and padded to fieldWidth with fillChar.
QString QString::arg(const char *a, int fieldWidth = 0, QChar fillChar = QChar(u' ')) const
This is an overloaded function.
Replaces the lowest-numbered %n place marker with the UTF-8 encoded string a, padded to fieldWidth with fillChar.
QString QString::arg(qlonglong a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const
This is an overloaded function.
Replaces the lowest-numbered place marker with the integer a written in base (2 to 36; other values mean 10), padded to fieldWidth with fillChar. When padding a negative number with '0', the zeros follow the minus sign. A marker written %L1 is replaced by the number as the default QLocale writes it, with group separators, when base is 10.
QString QString::arg(qulonglong a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const
This is an overloaded function.
Replaces the lowest-numbered place marker with the unsigned integer a written in base, padded to fieldWidth with fillChar.
QString QString::arg(long a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const
This is an overloaded function.
Replaces the lowest-numbered %n place marker with the integer a written in base, padded to fieldWidth with fillChar.
QString QString::arg(ulong a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const
This is an overloaded function.
Replaces the lowest-numbered %n place marker with the unsigned integer a written in base, padded to fieldWidth with fillChar.
QString QString::arg(int a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const
This is an overloaded function.
Replaces the lowest-numbered %n place marker with the integer a written in base, padded to fieldWidth with fillChar.
QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const
This is an overloaded function.
Replaces the lowest-numbered %n place marker with the unsigned integer a written in base, padded to fieldWidth with fillChar.
QString QString::arg(short a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const
This is an overloaded function.
Replaces the lowest-numbered %n place marker with the integer a written in base, padded to fieldWidth with fillChar.
QString QString::arg(ushort a, int fieldWidth = 0, int base = 10, QChar fillChar = QChar(u' ')) const
This is an overloaded function.
Replaces the lowest-numbered %n place marker with the unsigned integer a written in base, padded to fieldWidth with fillChar.
QString QString::arg(double a, int fieldWidth = 0, char format = 'g', int precision = -1, QChar fillChar = QChar(u' ')) const
This is an overloaded function.
Replaces the lowest-numbered place marker with the floating-point value a, formatted as described for number() using format and precision, and padded to fieldWidth with fillChar. A marker written %L1 is replaced by the value as the default QLocale writes it.
template <typename A1, typename A2, typename... Rest, typename = std::enable_if_t<!std::is_arithmetic_v<A1> && !std::is_arithmetic_v<A2> && (!std::is_arithmetic_v<Rest> && ...)>>QString QString::arg(const A1 &a1, const A2 &a2, const Rest &...rest) const
This is an overloaded function.
Replaces the lowest-numbered place marker with a1, the next one with a2, and each further one with the corresponding argument of rest. Every argument is converted to a QString. The markers are replaced in one pass, so a marker inside an argument is left alone: QString("%1 %2").arg("%2", "x") is "%2 x". An argument that has no marker is dropped. This overload only takes part in overload resolution when none of the arguments is an arithmetic type.
QString QString::asprintf(const char *fmt, ...)
Returns a string built from the printf()-style format fmt and the following arguments. fmt is interpreted as UTF-8, and the output of vsnprintf() is decoded as UTF-8.
See also vasprintf() and arg().
QString & QString::assign(const QAnyStringView &v)
Replaces the contents with the text of v, which may be Latin-1, UTF-8 or UTF-16, and returns a reference to this string.
QString s;
s.assign("utf-8 text");
s.assign(u"utf-16 text");
This function was introduced in 6.6.
QString & QString::assign(qsizetype n, QChar c)
Replaces the contents with n copies of c and returns a reference to this string.
This function was introduced in 6.6.
template <typename InputIterator, typename = typename std::iterator_traits<InputIterator>::iterator_category>QString & QString::assign(InputIterator first, InputIterator last)
This is an overloaded function.
Replaces the contents with the characters in the range [first, last), each of which must convert to QChar, and returns a reference to this string.
This function was introduced in 6.6.
QChar QString::at(qsizetype i) const
Returns the character at index position i. i must be a valid index; the behavior is undefined otherwise.
QChar QString::back() const
Returns the last character of the string. The string must not be empty.
iterator QString::begin()
Returns an iterator pointing to the first character of the string.
See also end() and constBegin().
const_iterator QString::begin() const
This is an overloaded function.
Returns a const iterator pointing to the first character of the string.
qsizetype QString::capacity() const
Returns the number of characters the string can hold without reallocating.
See also reserve() and squeeze().
const_iterator QString::cbegin() const
Returns a const iterator pointing to the first character of the string.
const_iterator QString::cend() const
Returns a const iterator pointing just after the last character of the string.
void QString::chop(qsizetype n)
Removes n characters from the end of the string. If n is greater than or equal to size(), the string becomes empty.
See also truncate() and chopped().
QString QString::chopped(qsizetype n) const
Returns the string with the last n characters removed. If n is larger than size(), the result is the whole string.
void QString::clear()
Clears the contents of the string and makes it null.
See also isNull() and resize().
int QString::compare(const QString &o, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Compares this string with o, using the case sensitivity cs, and returns a negative integer, zero or a positive integer if this string is less than, equal to or greater than o. Strings are compared code unit by code unit (after case folding with toLower() if cs is Qt::CaseInsensitive); the comparison is not locale aware.
See also localeAwareCompare().
int QString::compare(const QString &a, const QString &b, Qt::CaseSensitivity cs = Qt::CaseSensitive)
This is an overloaded function.
Compares the strings a and b using the case sensitivity cs.
const_iterator QString::constBegin() const
Returns a const iterator pointing to the first character of the string.
See also constEnd() and begin().
const QChar * QString::constData() const
Returns a pointer to the characters of the string. The data is null-terminated.
const_iterator QString::constEnd() const
Returns a const iterator pointing just after the last character of the string.
See also constBegin() and end().
bool QString::contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Returns true if the string contains an occurrence of the string s, using the case sensitivity cs; otherwise returns false.
See also indexOf() and count().
bool QString::contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Returns true if the string contains the character c, using the case sensitivity cs; otherwise returns false.
bool QString::contains(const QRegularExpression &re, QRegularExpressionMatch *rmatch = nullptr) const
Returns true if the regular expression re matches somewhere in this string; otherwise returns false. If rmatch is not nullptr and there is a match, the match is stored there.
This function was introduced in 5.0.
See also indexOf() and QRegularExpression::match().
qsizetype QString::count() const
This is an overloaded function.
Returns the number of characters in the string. This is the same as size().
qsizetype QString::count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Returns the number of occurrences of the string s in this string, using the case sensitivity cs. Overlapping occurrences are counted separately. Returns 0 if s is empty.
See also contains() and indexOf().
qsizetype QString::count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Returns the number of occurrences of the character c in the string, using the case sensitivity cs.
qsizetype QString::count(const QRegularExpression &re) const
Returns the number of times re matches in this string. Matches may overlap: after each match the search continues one character after where the match started.
This function was introduced in 5.0.
See also contains().
const_reverse_iterator QString::crbegin() const
Returns a const reverse iterator pointing to the last character of the string.
See also rbegin() and crend().
const_reverse_iterator QString::crend() const
Returns a const reverse iterator pointing just before the first character of the string.
See also rend() and crbegin().
QChar * QString::data()
Returns a pointer to the characters of the string, which can be used to modify them. The data is null-terminated.
See also constData() and utf16().
const QChar * QString::data() const
This is an overloaded function.
Returns a pointer to the characters of the string. The data is null-terminated.
iterator QString::end()
Returns an iterator pointing just after the last character of the string.
See also begin() and constEnd().
const_iterator QString::end() const
This is an overloaded function.
Returns a const iterator pointing just after the last character of the string.
bool QString::endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Returns true if the string ends with s, using the case sensitivity cs; otherwise returns false.
See also startsWith() and right().
bool QString::endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Returns true if the string ends with the character c, using the case sensitivity cs; otherwise returns false.
iterator QString::erase(const_iterator first, const_iterator last)
Removes the characters from first up to, but not including, last. Returns an iterator to the character that followed the last removed one.
This function was introduced in 6.1.
See also remove().
iterator QString::erase(const_iterator it)
This is an overloaded function.
Removes the character that it points to and returns an iterator to the character after it.
This function was introduced in 6.5.
QString & QString::fill(QChar c, qsizetype n = -1)
Sets every character of the string to c and returns a reference to it. If n is not negative the string is first resized to n characters; otherwise its size is unchanged. The string is no longer null afterwards.
See also resize().
QString QString::first(qsizetype n) const
Returns the first n characters of the string. This is the same as left().
QString QString::fromLatin1(const char *s, qsizetype size = -1)
Returns a string decoded from the first size bytes of the Latin-1 string s. If size is negative, s must be null-terminated. The result is null if s is nullptr.
See also toLatin1() and fromUtf8().
QString QString::fromLatin1(const QByteArray &b)
This is an overloaded function.
Returns a string decoded from the Latin-1 data in b.
QString QString::fromLatin1(QByteArrayView b)
This is an overloaded function.
Returns a string decoded from the Latin-1 data that the view b refers to. A std::string_view converts to such a view.
This function was introduced in 6.0.
QString QString::fromLocal8Bit(const char *s, qsizetype size = -1)
Returns a string decoded from the first size bytes of s, which is interpreted as UTF-8. If size is negative, s must be null-terminated. Nt always uses UTF-8 as the local 8-bit encoding.
See also fromUtf8() and toLocal8Bit().
QString QString::fromLocal8Bit(const QByteArray &b)
This is an overloaded function.
Returns a string decoded from the UTF-8 data in b.
QString QString::fromRawData(const QChar *u, qsizetype size)
Returns a string holding a copy of the first size characters of u. Unlike in Qt, the data is copied, not referenced, so u does not need to stay valid.
QString QString::fromStdString(const std::string &s)
Returns a string decoded from the UTF-8 encoded std::string s.
See also toStdString() and fromUtf8().
QString QString::fromStdU16String(const std::u16string &s)
Returns a string holding a copy of the std::u16string s.
See also toStdU16String().
QString QString::fromStdU32String(const std::u32string &s)
Returns a string holding the code points of s.
This function was introduced in 5.5.
See also toStdU32String() and fromUcs4().
QString QString::fromStdWString(const std::wstring &s)
Returns a string decoded from s, as UTF-32 or UTF-16 depending on the size of wchar_t.
See also toStdWString() and fromWCharArray().
QString QString::fromUcs4(const char32_t *unicode, qsizetype size = -1)
Returns a string holding the first size code points of unicode; if size is negative, unicode must end with a 0. Code points that are not valid become U+FFFD.
See also toUcs4().
QString QString::fromUtf16(const char16_t *s, qsizetype size = -1)
Returns a string holding a copy of the first size code units of s. If size is negative, s must be null-terminated. The result is null if s is nullptr.
See also utf16().
QString QString::fromUtf8(const char *s, qsizetype size = -1)
Returns a string decoded from the first size bytes of the UTF-8 string s. If size is negative, s must be null-terminated. Invalid sequences are replaced by U+FFFD. The result is null if s is nullptr.
See also toUtf8() and fromLatin1().
QString QString::fromUtf8(const QByteArray &b)
This is an overloaded function.
Returns a string decoded from the UTF-8 data in b.
QString QString::fromWCharArray(const wchar_t *string, qsizetype size = -1)
Returns a string decoded from the first size values of string, as UTF-32 where wchar_t is 32 bits and UTF-16 where it is 16 bits. If size is negative, string must end with a 0.
See also toWCharArray() and fromStdWString().
QChar QString::front() const
Returns the first character of the string. The string must not be empty.
qsizetype QString::indexOf(const QString &s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Returns the index position of the first occurrence of the string s in this string, searching forward from index position from, or -1 if it is not found. If from is negative, it is counted from the end of the string. cs selects the case sensitivity.
See also lastIndexOf(), contains() and count().
qsizetype QString::indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Returns the index position of the first occurrence of the character c in the string, searching forward from index position from, or -1 if it is not found. cs selects the case sensitivity.
qsizetype QString::indexOf(const QRegularExpression &re, qsizetype from = 0, QRegularExpressionMatch *rmatch = nullptr) const
Returns the index position of the first match of re in this string, searching forward from from, or -1 if there is none. If rmatch is not nullptr and there is a match, the match is stored there.
This function was introduced in 5.0.
See also lastIndexOf() and contains().
QString & QString::insert(qsizetype pos, const QString &s)
Inserts the string s at index position pos and returns a reference to this string. pos must be between 0 and size().
See also append(), prepend() and remove().
QString & QString::insert(qsizetype pos, QChar c)
This is an overloaded function.
Inserts the character c at index position pos.
bool QString::isEmpty() const
Returns true if the string has no characters; otherwise returns false.
bool QString::isLower() const
Returns true if the string equals its toLower().
This function was introduced in 5.12.
See also isUpper() and toLower().
bool QString::isNull() const
Returns true if the string is null, that is, default-constructed (or cleared) and never given any content; otherwise returns false. A null string is also empty.
See also isEmpty() and clear().
bool QString::isRightToLeft() const
Returns true if the string reads right to left: if its first strong character outside directional isolates (see QChar::direction()) is right-to-left. Returns false otherwise, including when it has no strong character.
bool QString::isUpper() const
Returns true if the string equals its toUpper(), that is, if it has no character that uppercasing would change. The empty string is uppercase.
This function was introduced in 5.12.
See also isLower() and toUpper().
bool QString::isValidUtf16() const
Returns true if the string is valid UTF-16: every high surrogate is followed by a low surrogate and no low surrogate stands alone.
This function was introduced in 5.15.
QString QString::last(qsizetype n) const
Returns the last n characters of the string. This is the same as right().
qsizetype QString::lastIndexOf(const QString &s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Returns the index position of the last occurrence of the string s in this string, searching backward from index position from, or -1 if it is not found. A negative from is counted from the end of the string, so the default of -1 starts at the last character. The match must begin at or before from. cs selects the case sensitivity.
See also indexOf() and contains().
qsizetype QString::lastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Returns the index position of the last occurrence of the character c in the string, searching backward from index position from, or -1 if it is not found. cs selects the case sensitivity.
qsizetype QString::lastIndexOf(const QRegularExpression &re, QRegularExpressionMatch *rmatch = nullptr) const
Returns the index position of the last match of re in this string, or -1 if there is none. If rmatch is not nullptr and there is a match, the match is stored there.
This function was introduced in 5.0.
See also indexOf().
qsizetype QString::lastIndexOf(const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch = nullptr) const
This is an overloaded function.
Returns the index position of the last match of re that starts at or before from, or -1. A negative from counts from the end.
This function was introduced in 5.0.
QString QString::left(qsizetype n) const
Returns the first n characters of the string, or the whole string if n is greater than size() or negative.
See also right(), mid() and first().
QString QString::leftJustified(qsizetype width, QChar fill = QChar(u' '), bool truncate = false) const
Returns a string of the given width containing this string padded on the right with fill. If the string is longer than width, it is returned unchanged, or cut to width characters if truncate is true.
See also rightJustified().
qsizetype QString::length() const
Returns the number of characters in the string. This is the same as size().
int QString::localeAwareCompare(const QString &a, const QString &b)
Compares a with b in the collation order of the default locale and returns a negative number, zero or a positive number if a sorts before, equal to or after b.
See also QCollator.
qsizetype QString::max_size() const
Returns the largest number of characters a string can theoretically hold.
This function was introduced in 6.8.
See also maxSize().
qsizetype QString::maxSize()
Returns the largest number of characters a string can theoretically hold.
This function was introduced in 6.8.
See also max_size().
QString QString::mid(qsizetype pos, qsizetype len = -1) const
Returns a string containing len characters starting at index position pos. If len is negative or extends past the end, the result extends to the end of the string. A negative pos is clamped to 0 and reduces len accordingly. If pos is past the end of the string, or len is 0, the result is an empty, non-null string.
See also left(), right() and sliced().
QString QString::normalized(NormalizationForm mode) const
Returns the string in the Unicode normalization form mode. Use NormalizationForm_C to store and compare text, and the compatibility forms (KD, KC) to match characters that only differ in presentation, such as "fi" and "fi".
QString(u"e\u0301"_s).normalized(QString::NormalizationForm_C); // "é", one character
See also QChar::decomposition() and QChar::combiningClass().
QString & QString::nullTerminate()
Makes sure that the characters are followed by a '\0' and returns a reference to this string. Nt keeps strings null-terminated already, so this only clears the null state of a null string.
This function was introduced in 6.5.
See also nullTerminated().
QString QString::nullTerminated() const
Returns a copy of the string whose characters are followed by a '\0'.
This function was introduced in 6.5.
See also nullTerminate().
QString QString::number(qlonglong n, int base = 10)
Returns a string holding the representation of the integer n in base (2 to 36; other values mean 10). Digits above 9 are lowercase letters.
See also setNum(), toInt() and toLongLong().
QString QString::number(qulonglong n, int base = 10)
This is an overloaded function.
Returns a string holding the representation of the unsigned integer n in base.
QString QString::number(int n, int base = 10)
This is an overloaded function.
Returns a string holding the representation of the integer n in base.
QString QString::number(uint n, int base = 10)
This is an overloaded function.
Returns a string holding the representation of the unsigned integer n in base.
QString QString::number(long n, int base = 10)
This is an overloaded function.
Returns a string holding the representation of the integer n in base.
QString QString::number(ulong n, int base = 10)
This is an overloaded function.
Returns a string holding the representation of the unsigned integer n in base.
QString QString::number(double n, char format = 'g', int precision = 6)
This is an overloaded function.
Returns a string holding the representation of the floating-point value n. format is one of 'f' (fixed), 'e' (scientific) or 'g' (the shorter of the two), with an uppercase letter selecting an uppercase exponent; any other value is treated as 'g'. precision is the number of digits after the decimal point for 'f' and 'e', or the number of significant digits for 'g'. If precision is negative, the shortest representation that round-trips is produced. The C locale is always used.
See also toDouble() and setNum().
QString & QString::operator+=(const QString &s)
Appends the string s to this string and returns a reference to it.
See also append().
QString & QString::operator+=(QChar c)
This is an overloaded function.
Appends the character c to this string.
QString & QString::operator+=(const char *s)
This is an overloaded function.
Appends the UTF-8 encoded string s to this string.
QChar QString::operator[](qsizetype i) const
This is an overloaded function.
Returns the character at index position i. This is the same as at().
QChar & QString::operator[](qsizetype i)
This is an overloaded function.
Returns a reference to the character at index position i, which can be used to modify it. i must be a valid index.
QString & QString::prepend(const QString &s)
Prepends the string s to this string and returns a reference to it.
See also append() and insert().
QString & QString::prepend(QChar c)
This is an overloaded function.
Prepends the character c to this string.
void QString::push_back(QChar c)
Appends the character c to this string. This function is provided for STL compatibility.
See also append().
void QString::push_back(const QString &s)
This is an overloaded function.
Appends the string s to this string.
void QString::push_front(QChar c)
Inserts c at the beginning of the string. Provided for compatibility with the standard library.
See also prepend() and push_back().
void QString::push_front(const QString &s)
This is an overloaded function.
Inserts s at the beginning of the string.
reverse_iterator QString::rbegin()
Returns a reverse iterator pointing to the last character of the string.
See also rend() and crbegin().
const_reverse_iterator QString::rbegin() const
This is an overloaded function.
QString & QString::remove(qsizetype pos, qsizetype len)
Removes len characters from the string starting at index position pos and returns a reference to the string. Nothing happens if pos is out of range or len is not positive.
See also insert(), replace() and chop().
QString & QString::remove(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive)
This is an overloaded function.
Removes every occurrence of the string s from this string, using the case sensitivity cs, and returns a reference to this string.
QString & QString::remove(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive)
This is an overloaded function.
Removes every occurrence of the character c from this string, using the case sensitivity cs.
QString & QString::remove(const QRegularExpression &re)
Removes every match of re from this string and returns a reference to the string.
This function was introduced in 5.0.
See also replace().
QString & QString::removeAt(qsizetype pos)
Removes the character at index position pos and returns a reference to this string. Nothing happens if pos is out of range.
This function was introduced in 6.5.
See also remove(), removeFirst() and removeLast().
QString & QString::removeFirst()
Removes the first character and returns a reference to this string. Nothing happens if the string is empty.
This function was introduced in 6.5.
See also removeLast() and removeAt().
template <typename Predicate>QString & QString::removeIf(Predicate pred)
Removes every character for which pred returns true and returns a reference to this string. pred is called with a QChar.
This function was introduced in 6.1.
See also remove().
QString & QString::removeLast()
Removes the last character and returns a reference to this string. Nothing happens if the string is empty.
This function was introduced in 6.5.
See also removeFirst() and chop().
reverse_iterator QString::rend()
Returns a reverse iterator pointing just before the first character of the string.
See also rbegin() and crend().
const_reverse_iterator QString::rend() const
This is an overloaded function.
QString QString::repeated(qsizetype times) const
Returns a copy of this string repeated times times. An empty string is returned if times is less than 1.
QString & QString::replace(qsizetype pos, qsizetype len, const QString &after)
Replaces len characters starting at index position pos with the string after and returns a reference to this string. If len extends past the end, the rest of the string is replaced. A negative len is treated as 0, which inserts after. Nothing happens if pos is out of range.
See also insert() and remove().
QString & QString::replace(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
This is an overloaded function.
Replaces every occurrence of the string before with the string after, using the case sensitivity cs, and returns a reference to this string. Nothing happens if before is empty. Replaced text is not searched again.
QString & QString::replace(QChar before, QChar after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
This is an overloaded function.
Replaces every occurrence of the character before with the character after, using the case sensitivity cs.
QString & QString::replace(QChar before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
This is an overloaded function.
Replaces every occurrence of the character before with the string after, using the case sensitivity cs.
QString & QString::replace(const QRegularExpression &re, const QString &after)
Replaces every match of re in this string with after and returns a reference to the string. In after, \1 to \99 stand for the text captured by the corresponding group; a two-digit reference is used only if the expression has that many groups.
This function was introduced in 5.0.
See also remove().
void QString::reserve(qsizetype n)
Ensures the string has room for at least n characters without reallocating.
See also capacity() and squeeze().
void QString::resize(qsizetype n)
Sets the size of the string to n characters. If n is greater than the current size, the new characters are set to U+0000. The string is no longer null afterwards.
See also size() and truncate().
void QString::resize(qsizetype n, QChar c)
This is an overloaded function.
Sets the size of the string to n characters. If n is greater than the current size, the new characters are set to c.
void QString::resizeForOverwrite(qsizetype size)
Sets the size of the string to size characters, for a caller that is about to assign every new character. Nt sets them to U+0000.
This function was introduced in 6.8.
See also resize().
QString QString::right(qsizetype n) const
Returns the last n characters of the string, or the whole string if n is greater than size().
See also left(), mid() and last().
QString QString::rightJustified(qsizetype width, QChar fill = QChar(u' '), bool truncate = false) const
Returns a string of the given width containing this string padded on the left with fill. If the string is longer than width, it is returned unchanged, or cut to width characters if truncate is true.
See also leftJustified().
QString QString::section(QChar sep, qsizetype start, qsizetype end = -1) const
Splits the string at every occurrence of the character sep and returns the fields numbered start to end (inclusive), joined by sep. Negative field numbers count from the last field. An empty string is returned if the range is empty. If end is -1, all fields from start on are returned.
See also split().
QString QString::section(const QString &sep, qsizetype start, qsizetype end = -1) const
This is an overloaded function.
Splits the string at every occurrence of sep and returns the fields numbered start to end (inclusive), joined by sep. Negative field numbers count from the last field. An empty string is returned if the range is empty. If end is -1, all fields from start on are returned.
See also split().
QString & QString::setNum(qlonglong n, int base = 10)
Sets the string to the representation of n in base and returns a reference to it.
See also number().
QString & QString::setNum(qulonglong n, int base = 10)
This is an overloaded function.
Sets the string to the representation of the unsigned integer n in base.
QString & QString::setNum(int n, int base = 10)
This is an overloaded function.
Sets the string to the representation of the integer n in base.
QString & QString::setNum(uint n, int base = 10)
This is an overloaded function.
Sets the string to the representation of the unsigned integer n in base.
QString & QString::setNum(double n, char format = 'g', int precision = 6)
This is an overloaded function.
Sets the string to the representation of the floating-point value n, formatted with format and precision as described for number().
QString & QString::setRawData(const QChar *unicode, qsizetype size)
Replaces the contents with a copy of the size characters at unicode and returns a reference to this string. Unlike in Qt, the data is copied.
See also fromRawData().
QString & QString::setUnicode(const QChar *unicode, qsizetype size)
Replaces the contents with the size characters at unicode and returns a reference to this string. If unicode is nullptr, the string is only resized to size.
See also setUtf16() and setRawData().
QString & QString::setUtf16(const char16_t *utf16, qsizetype size)
Replaces the contents with the size UTF-16 code units at utf16 and returns a reference to this string.
See also setUnicode().
void QString::shrink_to_fit()
Releases memory that is not needed to hold the characters. Provided for compatibility with the standard library.
See also squeeze().
QString QString::simplified() const
Returns a copy of the string with white space removed from the start and the end, and every internal run of white space replaced by a single space.
See also trimmed() and QChar::isSpace().
qsizetype QString::size() const
Returns the number of characters (UTF-16 code units) in the string.
See also length(), isEmpty() and resize().
QString & QString::slice(qsizetype pos)
Removes the characters before index position pos and returns a reference to this string.
This function was introduced in 6.8.
See also sliced().
QString & QString::slice(qsizetype pos, qsizetype n)
This is an overloaded function.
Keeps the n characters starting at index position pos and returns a reference to this string.
This function was introduced in 6.8.
QString QString::sliced(qsizetype pos, qsizetype n) const
Returns n characters of the string starting at index position pos. This is the same as mid().
QString QString::sliced(qsizetype pos) const
This is an overloaded function.
Returns the part of the string starting at index position pos and extending to the end.
QStringList QString::split(const QString &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Splits the string into substrings wherever sep occurs and returns the list of those strings. behavior selects whether empty parts are kept or skipped, and cs the case sensitivity of the match. If sep is empty, the result holds an empty part, one part for each character, and another empty part (the empty parts are dropped if behavior is Qt::SkipEmptyParts).
See also QStringList::join() and section().
QStringList QString::split(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Splits the string into substrings wherever the character sep occurs. behavior selects whether empty parts are kept or skipped, and cs the case sensitivity of the match.
QStringList QString::split(const QRegularExpression &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const
Splits the string into substrings wherever sep matches and returns the list of those substrings. behavior selects whether empty substrings are kept.
This function was introduced in 5.14.
See also QStringList::join().
void QString::squeeze()
Releases any memory not needed to store the characters.
See also reserve() and capacity().
bool QString::startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
Returns true if the string starts with s, using the case sensitivity cs; otherwise returns false.
See also endsWith() and left().
bool QString::startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
This is an overloaded function.
Returns true if the string starts with the character c, using the case sensitivity cs; otherwise returns false.
void QString::swap(QString &o)
Swaps this string with o. This operation is very fast and never fails.
QString QString::toCaseFolded() const
Returns the case folded equivalent of the string, for comparing text regardless of case. Full case folding is used, so "Straße" folds to "strasse".
See also toLower() and compare().
double QString::toDouble(bool *ok = nullptr) const
Returns the string converted to a double. Leading and trailing white space is ignored. The conversion uses the C locale and accepts what strtod() accepts, including exponents, inf and nan. If ok is not nullptr, it is set to true on success and false on failure (an empty string, trailing characters, non-ASCII characters or overflow), in which case 0 is returned.
See also number() and toFloat().
float QString::toFloat(bool *ok = nullptr) const
Returns the string converted to a float. The string is converted with toDouble() and then narrowed; ok is set as described there.
See also toDouble().
QString QString::toHtmlEscaped() const
Returns a copy of the string with the HTML metacharacters <, >, & and " replaced by their entities, for inclusion in HTML text or attribute values.
int QString::toInt(bool *ok = nullptr, int base = 10) const
Returns the string converted to an int using base. Conversion follows toLongLong(), and also fails if the value does not fit in an int. On failure ok is set to false (if it is not nullptr) and 0 is returned.
See also toLongLong() and number().
template <typename Needle, typename... Flags>auto QString::tokenize(Needle &&needle, Flags... flags) const &
Returns a tokenizer that splits this string at each occurrence of needle without copying the parts: each token is a QStringView of this string, which must stay alive and unchanged while the tokenizer is used. flags may hold a Qt::SplitBehavior and a Qt::CaseSensitivity, in either order. Include <QStringTokenizer> to use this function.
This function was introduced in 6.0.
See also QStringTokenizer and split().
template <typename Needle, typename... Flags>auto QString::tokenize(Needle &&needle, Flags... flags) &&
This is an overloaded function.
Returns a tokenizer for a temporary string, splitting it at each occurrence of needle according to flags. The string is moved into the tokenizer, so the tokens stay valid for as long as the tokenizer lives.
This function was introduced in 6.0.
QByteArray QString::toLatin1() const
Returns the string as a Latin-1 encoded byte array. Characters outside the range U+0000 to U+00FF are replaced by '?'.
See also fromLatin1() and toUtf8().
QByteArray QString::toLocal8Bit() const
Returns the string as a UTF-8 encoded byte array. Nt always uses UTF-8 as the local 8-bit encoding.
See also toUtf8() and fromLocal8Bit().
long QString::toLong(bool *ok = nullptr, int base = 10) const
Returns the string converted to a long using base. Conversion follows toLongLong(), and also fails if the value does not fit in a long. On failure ok is set to false (if it is not nullptr) and 0 is returned.
See also toLongLong() and toInt().
qlonglong QString::toLongLong(bool *ok = nullptr, int base = 10) const
Returns the string converted to a long long using base, which must be between 2 and 36 or 0. If base is 0, the C prefixes 0x and 0 select hexadecimal and octal, and decimal is used otherwise. Leading and trailing white space is ignored. If ok is not nullptr, it is set to true on success and false on failure (for example when the string is empty, has other trailing characters, contains non-ASCII characters or the value overflows), in which case 0 is returned. The C locale is always used.
See also number(), toULongLong() and toInt().
QString QString::toLower() const
Returns a lowercase copy of the string, using the full case mappings of Unicode.
See also toUpper(), toCaseFolded() and QChar::toLower().
short QString::toShort(bool *ok = nullptr, int base = 10) const
Returns the string converted to a short using base. Conversion follows toLongLong(), and also fails if the value does not fit in a short. On failure ok is set to false (if it is not nullptr) and 0 is returned.
See also toInt() and toUShort().
std::string QString::toStdString() const
Returns the string as a UTF-8 encoded std::string.
See also fromStdString().
std::u16string QString::toStdU16String() const
Returns a copy of the string as a std::u16string.
See also fromStdU16String() and u16string().
std::u32string QString::toStdU32String() const
Returns the string as a std::u32string of code points. Unpaired surrogates become U+FFFD.
This function was introduced in 5.4.
See also fromStdU32String() and toUcs4().
std::wstring QString::toStdWString() const
Returns the string as a std::wstring. wchar_t is 32 bits on Linux and macOS, where each element is a code point, and 16 bits on Windows, where it is a UTF-16 code unit.
See also fromStdWString() and toWCharArray().
QList<uint> QString::toUcs4() const
Returns the code points of the string. Unpaired surrogates become U+FFFD.
See also fromUcs4() and toStdU32String().
uint QString::toUInt(bool *ok = nullptr, int base = 10) const
Returns the string converted to an unsigned int using base. Conversion follows toULongLong(), and also fails if the value does not fit in an unsigned int. On failure ok is set to false (if it is not nullptr) and 0 is returned.
See also toInt() and toULongLong().
ulong QString::toULong(bool *ok = nullptr, int base = 10) const
Returns the string converted to an unsigned long using base. Conversion follows toULongLong(), and also fails if the value does not fit in an unsigned long. On failure ok is set to false (if it is not nullptr) and 0 is returned.
See also toULongLong() and toLong().
qulonglong QString::toULongLong(bool *ok = nullptr, int base = 10) const
Returns the string converted to an unsigned long long using base. Conversion follows toLongLong(), except that a leading minus sign makes the conversion fail. On failure ok is set to false (if it is not nullptr) and 0 is returned.
See also toLongLong() and number().
QString QString::toUpper() const
Returns an uppercase copy of the string, using the full case mappings of Unicode: characters such as U+00DF ("ß") become several characters ("SS"), so the result can be longer. Characters outside the Basic Multilingual Plane are converted too.
See also toLower(), toCaseFolded() and QChar::toUpper().
ushort QString::toUShort(bool *ok = nullptr, int base = 10) const
Returns the string converted to an unsigned short using base. Conversion follows toULongLong(), and also fails if the value does not fit in an unsigned short. On failure ok is set to false (if it is not nullptr) and 0 is returned.
See also toShort() and toUInt().
QByteArray QString::toUtf8() const
Returns the string as a UTF-8 encoded byte array. Unpaired surrogates are encoded as U+FFFD. A null string gives a null byte array.
See also fromUtf8() and toLatin1().
qsizetype QString::toWCharArray(wchar_t *array) const
Writes the string to array as wchar_t values, UTF-32 where wchar_t is 32 bits and UTF-16 where it is 16 bits, and returns how many were written. array must have room for size() values; no terminating 0 is written.
See also fromWCharArray() and toStdWString().
QString QString::trimmed() const
Returns a copy of the string with white space removed from the start and the end.
See also simplified() and QChar::isSpace().
void QString::truncate(qsizetype pos)
Truncates the string at index position pos. If pos is beyond the end of the string, nothing happens; a negative pos empties the string.
See also chop(), resize() and left().
const std::u16string & QString::u16string() const
Returns a reference to the underlying std::u16string.
See also toStdU16String() and utf16().
const QChar * QString::unicode() const
Returns a pointer to the characters of the string, followed by a '\0'. Same as constData().
const char16_t * QString::utf16() const
Returns the string as a null-terminated array of UTF-16 code units.
See also constData() and u16string().
QString QString::vasprintf(const char *fmt, va_list ap)
Returns a string built from the printf()-style format fmt and the argument list ap, like asprintf(). ap is left unchanged.
See also asprintf().