![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
#include <qstring.h>
Public Types | |
enum | SectionFlag { SectionDefault = 0x00 , SectionSkipEmpty = 0x01 , SectionIncludeLeadingSep = 0x02 , SectionIncludeTrailingSep = 0x04 , SectionCaseInsensitiveSeps = 0x08 } |
This enum specifies flags that can be used to affect various aspects of the section() function's behavior with respect to separators and empty fields. More... | |
enum | NormalizationForm { NormalizationForm_D , NormalizationForm_C , NormalizationForm_KD , NormalizationForm_KC } |
This enum describes the various normalized forms of Unicode text. More... | |
typedef QStringPrivate | DataPointer |
typedef QChar * | iterator |
typedef const QChar * | const_iterator |
typedef iterator | Iterator |
Qt-style synonym for QString::iterator. | |
typedef const_iterator | ConstIterator |
\macro QT_RESTRICTED_CAST_FROM_ASCII | |
typedef std::reverse_iterator< iterator > | reverse_iterator |
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
typedef qsizetype | size_type |
typedef qptrdiff | difference_type |
typedef const QChar & | const_reference |
typedef QChar & | reference |
typedef QChar * | pointer |
The QString::pointer typedef provides an STL-style pointer to a QString element (QChar). | |
typedef const QChar * | const_pointer |
The QString::const_pointer typedef provides an STL-style const pointer to a QString element (QChar). | |
typedef QChar | value_type |
Public Member Functions | |
constexpr | QString () noexcept |
Constructs a null string. | |
QString (const QChar *unicode, qsizetype size=-1) | |
Constructs a string initialized with the first size characters of the QChar array unicode. | |
QString (QChar c) | |
Constructs a string of size 1 containing the character ch. | |
QString (qsizetype size, QChar c) | |
Constructs a string of the given size with every character set to ch. | |
QString (QLatin1StringView latin1) | |
Constructs a copy of the Latin-1 string viewed by str. | |
QString (QStringView sv) | |
QString (const QString &) noexcept | |
Constructs a copy of other. | |
~QString () | |
Destroys the string. | |
QString & | operator= (QChar c) |
QString & | operator= (const QString &) noexcept |
Assigns other to this string and returns a reference to this string. | |
QString & | operator= (QLatin1StringView latin1) |
QString (QString &&other) noexcept=default | |
Move-constructs a QString instance, making it point at the same object that other was pointing to. | |
void | swap (QString &other) noexcept |
constexpr qsizetype | size () const noexcept |
Returns the number of characters in this string. | |
constexpr qsizetype | length () const noexcept |
Returns the number of characters in this string. | |
constexpr bool | isEmpty () const noexcept |
Returns true if the string has no characters; otherwise returns false . | |
void | resize (qsizetype size) |
Sets the size of the string to size characters. | |
void | resize (qsizetype size, QChar fillChar) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | resizeForOverwrite (qsizetype size) |
QString & | fill (QChar c, qsizetype size=-1) |
Sets every character in the string to character ch. | |
void | truncate (qsizetype pos) |
Truncates the string starting from, and including, the element at index position. | |
void | chop (qsizetype n) |
Removes n characters from the end of the string. | |
QString & | slice (qsizetype pos) |
QString & | slice (qsizetype pos, qsizetype n) |
qsizetype | capacity () const |
Returns the maximum number of characters that can be stored in the string without forcing a reallocation. | |
void | reserve (qsizetype size) |
Ensures the string has space for at least size characters. | |
void | squeeze () |
Releases any memory not required to store the character data. | |
const QChar * | unicode () const |
Returns a Unicode representation of the string. | |
QChar * | data () |
Returns a pointer to the data stored in the QString. | |
const QChar * | data () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QChar * | constData () const |
Returns a pointer to the data stored in the QString. | |
void | detach () |
bool | isDetached () const |
bool | isSharedWith (const QString &other) const |
void | clear () |
Clears the contents of the string and makes it null. | |
const QChar | at (qsizetype i) const |
Returns the character at the given index position in the string. | |
const QChar | operator[] (qsizetype i) const |
QChar & | operator[] (qsizetype i) |
Returns the character at the specified position in the string as a modifiable reference. | |
QChar | front () const |
QChar & | front () |
QChar | back () const |
QChar & | back () |
template<typename T, if_integral_non_char< T > = true> | |
QString | arg (T a, int fieldWidth=0, int base=10, QChar fillChar=u' ') const |
template<typename T, if_floating_point< T > = true> | |
QString | arg (T a, int fieldWidth=0, char format='g', int precision=-1, QChar fillChar=u' ') const |
template<typename T, if_string_like< T > = true> | |
QString | arg (const T &a, int fieldWidth=0, QChar fillChar=u' ') const |
Returns a copy of this string with the lowest-numbered place-marker replaced by string a, i.e., %1 , %2 , ..., %99 . | |
template<typename... Args> | |
std::enable_if< sizeof...(Args)>=2 &&std::conjunction_v< is_string_like< Args >... >, QString >::type | arg (Args &&...args) const |
static QString static QString | QT_CORE_INLINE_SINCE (6, 8) qsizetype indexOf(QChar c |
qsizetype | indexOf (QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
qsizetype | indexOf (const QString &s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
qsizetype | indexOf (QStringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
qsizetype | lastIndexOf (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
QT_CORE_INLINE_SINCE (6, 8) qsizetype lastIndexOf(QChar c | |
qsizetype | lastIndexOf (QLatin1StringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
qsizetype | lastIndexOf (QLatin1StringView s, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
qsizetype | lastIndexOf (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
qsizetype | lastIndexOf (const QString &s, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
qsizetype | lastIndexOf (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
qsizetype | lastIndexOf (QStringView s, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
bool | contains (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
bool | contains (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
Returns true if this string contains an occurrence of the string str; otherwise returns false . | |
bool | contains (QLatin1StringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
bool | contains (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
qsizetype | count (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
qsizetype | count (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
Returns the number of (potentially overlapping) occurrences of the string str in this string. | |
qsizetype | count (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
QString | section (QChar sep, qsizetype start, qsizetype end=-1, SectionFlags flags=SectionDefault) const |
This function returns a section of the string. | |
QString | section (const QString &in_sep, qsizetype start, qsizetype end=-1, SectionFlags flags=SectionDefault) const |
QString | left (qsizetype n) const & |
QString | left (qsizetype n) && |
QString | right (qsizetype n) const & |
QString | right (qsizetype n) && |
QString | mid (qsizetype position, qsizetype n=-1) const & |
QString | mid (qsizetype position, qsizetype n=-1) && |
QString | first (qsizetype n) const & |
QString | last (qsizetype n) const & |
QString | sliced (qsizetype pos) const & |
QString | sliced (qsizetype pos, qsizetype n) const & |
QString | chopped (qsizetype n) const & |
QString | first (qsizetype n) && |
QString | last (qsizetype n) && |
QString | sliced (qsizetype pos) && |
QString | sliced (qsizetype pos, qsizetype n) && |
QString | chopped (qsizetype n) && |
bool | startsWith (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
Returns true if the string starts with s; otherwise returns false . | |
bool | startsWith (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
bool | startsWith (QLatin1StringView 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 |
Returns true if the string ends with s; otherwise returns false . | |
bool | endsWith (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
bool | endsWith (QLatin1StringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
bool | endsWith (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
bool | isUpper () const |
Returns true if the string is uppercase, that is, it's identical to its toUpper() folding. | |
bool | isLower () const |
Returns true if the string is lowercase, that is, it's identical to its toLower() folding. | |
QString | leftJustified (qsizetype width, QChar fill=u' ', bool trunc=false) const |
Returns a string of size width that contains this string padded by the fill character. | |
QString | rightJustified (qsizetype width, QChar fill=u' ', bool trunc=false) const |
Returns a string of size() width that contains the fill character followed by the string. | |
QString | toLower () const & |
QString | toLower () && |
QString | toUpper () const & |
QString | toUpper () && |
QString | toCaseFolded () const & |
QString | toCaseFolded () && |
QString | trimmed () const & |
QString | trimmed () && |
QString | simplified () const & |
QString | simplified () && |
QString | toHtmlEscaped () const |
QString & | insert (qsizetype i, QChar c) |
QString & | insert (qsizetype i, const QChar *uc, qsizetype len) |
QString & | insert (qsizetype i, const QString &s) |
QString & | insert (qsizetype i, QStringView v) |
QString & | insert (qsizetype i, QLatin1StringView s) |
QString & | insert (qsizetype i, QUtf8StringView s) |
QString & | append (QChar c) |
QString & | append (const QChar *uc, qsizetype len) |
QString & | append (const QString &s) |
Appends the string str onto the end of this string. | |
QString & | append (QStringView v) |
QString & | append (QLatin1StringView s) |
QString & | append (QUtf8StringView s) |
QString & | prepend (QChar c) |
QString & | prepend (const QChar *uc, qsizetype len) |
QString & | prepend (const QString &s) |
Prepends the string str to the beginning of this string and returns a reference to this string. | |
QString & | prepend (QStringView v) |
QString & | prepend (QLatin1StringView s) |
QString & | prepend (QUtf8StringView s) |
QString & | assign (QAnyStringView s) |
QString & | assign (qsizetype n, QChar c) |
template<typename InputIterator, if_compatible_iterator< InputIterator > = true> | |
QString & | assign (InputIterator first, InputIterator last) |
QString & | operator+= (QChar c) |
QString & | operator+= (const QString &s) |
Appends the string other onto the end of this string and returns a reference to this string. | |
QString & | operator+= (QStringView v) |
QString & | operator+= (QLatin1StringView s) |
QString & | operator+= (QUtf8StringView s) |
QString & | remove (qsizetype i, qsizetype len) |
Removes n characters from the string, starting at the given position index, and returns a reference to the string. | |
QString & | remove (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) |
Removes every occurrence of the character ch in this string, and returns a reference to this string. | |
QString & | remove (QLatin1StringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) |
QString & | remove (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) |
Removes every occurrence of the given str string in this string, and returns a reference to this string. | |
QString & | removeAt (qsizetype pos) |
QString & | removeFirst () |
QString & | removeLast () |
template<typename Predicate> | |
QString & | removeIf (Predicate pred) |
QString & | replace (qsizetype i, qsizetype len, QChar after) |
QString & | replace (qsizetype i, qsizetype len, const QChar *s, qsizetype slen) |
QString & | replace (qsizetype i, qsizetype len, const QString &after) |
Replaces n characters beginning at index position with the string after and returns a reference to this string. | |
QString & | replace (QChar before, QChar after, Qt::CaseSensitivity cs=Qt::CaseSensitive) |
QString & | replace (const QChar *before, qsizetype blen, const QChar *after, qsizetype alen, Qt::CaseSensitivity cs=Qt::CaseSensitive) |
QString & | replace (QLatin1StringView before, QLatin1StringView after, Qt::CaseSensitivity cs=Qt::CaseSensitive) |
QString & | replace (QLatin1StringView before, const QString &after, Qt::CaseSensitivity cs=Qt::CaseSensitive) |
QString & | replace (const QString &before, QLatin1StringView after, Qt::CaseSensitivity cs=Qt::CaseSensitive) |
QString & | replace (const QString &before, const QString &after, Qt::CaseSensitivity cs=Qt::CaseSensitive) |
QString & | replace (QChar c, const QString &after, Qt::CaseSensitivity cs=Qt::CaseSensitive) |
QString & | replace (QChar c, QLatin1StringView after, Qt::CaseSensitivity cs=Qt::CaseSensitive) |
QStringList | 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. | |
QStringList | split (QChar sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QStringList | split (const QRegularExpression &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts) const |
template<typename Needle, typename... Flags> | |
auto | tokenize (Needle &&needle, Flags...flags) const &noexcept(noexcept(qTokenize(std::declval< const QString & >(), std::forward< Needle >(needle), flags...))) -> decltype(qTokenize(*this, std::forward< Needle >(needle), flags...)) |
template<typename Needle, typename... Flags> | |
auto | tokenize (Needle &&needle, Flags...flags) const &&noexcept(noexcept(qTokenize(std::declval< const QString >(), std::forward< Needle >(needle), flags...))) -> decltype(qTokenize(std::move(*this), std::forward< Needle >(needle), flags...)) |
template<typename Needle, typename... Flags> | |
auto | tokenize (Needle &&needle, Flags...flags) &&noexcept(noexcept(qTokenize(std::declval< QString >(), std::forward< Needle >(needle), flags...))) -> decltype(qTokenize(std::move(*this), std::forward< Needle >(needle), flags...)) |
QString | normalized (NormalizationForm mode, QChar::UnicodeVersion version=QChar::Unicode_Unassigned) const |
Returns the string in the given Unicode normalization mode, according to the given version of the Unicode standard. | |
QString | repeated (qsizetype times) const |
const ushort * | utf16 () const |
Returns the QString as a '\0\'-terminated array of unsigned shorts. | |
QString | nullTerminated () const & |
QString | nullTerminated () && |
QString & | nullTerminate () |
QByteArray | toLatin1 () const & |
QByteArray | toLatin1 () && |
QByteArray | toUtf8 () const & |
QByteArray | toUtf8 () && |
QByteArray | toLocal8Bit () const & |
QByteArray | toLocal8Bit () && |
QList< uint > | toUcs4 () const |
qsizetype | toWCharArray (wchar_t *array) const |
QString & | setRawData (const QChar *unicode, qsizetype size) |
QString & | setUnicode (const QChar *unicode, qsizetype size) |
Resizes the string to size characters and copies unicode into the string. | |
Q_WEAK_OVERLOAD QString & | setUnicode (const char16_t *utf16, qsizetype size) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QString & | setUtf16 (const char16_t *utf16, qsizetype size) |
Q_WEAK_OVERLOAD QString & | setUtf16 (const ushort *autf16, qsizetype asize) |
\obsolete Use the char16_t overload instead. | |
int | compare (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
int | compare (QLatin1StringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
int | compare (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
int | compare (QChar ch, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept |
int | localeAwareCompare (const QString &s) const |
int | localeAwareCompare (QStringView s) const |
short | toShort (bool *ok=nullptr, int base=10) const |
Returns the string converted to a short using base base, which is 10 by default and must be between 2 and 36, or 0. | |
ushort | toUShort (bool *ok=nullptr, int base=10) const |
Returns the string converted to an {unsigned short} using base base, which is 10 by default and must be between 2 and 36, or 0. | |
int | toInt (bool *ok=nullptr, int base=10) const |
Returns the string converted to an int using base base, which is 10 by default and must be between 2 and 36, or 0. | |
uint | toUInt (bool *ok=nullptr, int base=10) const |
Returns the string converted to an {unsigned int} using base base, which is 10 by default and must be between 2 and 36, or 0. | |
long | toLong (bool *ok=nullptr, int base=10) const |
Returns the string converted to a long using base base, which is 10 by default and must be between 2 and 36, or 0. | |
ulong | toULong (bool *ok=nullptr, int base=10) const |
Returns the string converted to an {unsigned long} using base base, which is 10 by default and must be between 2 and 36, or 0. | |
qlonglong | toLongLong (bool *ok=nullptr, int base=10) const |
Returns the string converted to a {long long} using base base, which is 10 by default and must be between 2 and 36, or 0. | |
qulonglong | toULongLong (bool *ok=nullptr, int base=10) const |
Returns the string converted to an {unsigned long long} using base base, which is 10 by default and must be between 2 and 36, or 0. | |
float | toFloat (bool *ok=nullptr) const |
Returns the string converted to a float value. | |
double | toDouble (bool *ok=nullptr) const |
Returns the string converted to a double value. | |
QString & | setNum (short, int base=10) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QString & | setNum (ushort, int base=10) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QString & | setNum (int, int base=10) |
Sets the string to the printed value of n in the specified base, and returns a reference to the string. | |
QString & | setNum (uint, int base=10) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QString & | setNum (long, int base=10) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QString & | setNum (ulong, int base=10) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QString & | setNum (qlonglong, int base=10) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QString & | setNum (qulonglong, int base=10) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QString & | setNum (float, char format='g', int precision=6) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the string to the printed value of n, formatted according to the given format and precision, and returns a reference to the string. | |
QString & | setNum (double, char format='g', int precision=6) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the string to the printed value of n, formatted according to the given format and precision, and returns a reference to the string. | |
QT_ASCII_CAST_WARN | QString (const char *ch) |
Constructs a string initialized with the 8-bit string str. | |
QT_ASCII_CAST_WARN | QString (const QByteArray &a) |
Constructs a string initialized with the byte array ba. | |
QT_ASCII_CAST_WARN QString & | operator= (const char *ch) |
QT_ASCII_CAST_WARN QString & | operator= (const QByteArray &a) |
QT_ASCII_CAST_WARN QString & | prepend (const char *s) |
QT_ASCII_CAST_WARN QString & | prepend (const QByteArray &s) |
QT_ASCII_CAST_WARN QString & | append (const char *s) |
QT_ASCII_CAST_WARN QString & | append (const QByteArray &s) |
QT_ASCII_CAST_WARN QString & | insert (qsizetype i, const char *s) |
QT_ASCII_CAST_WARN QString & | insert (qsizetype i, const QByteArray &s) |
QT_ASCII_CAST_WARN QString & | operator+= (const char *s) |
QT_ASCII_CAST_WARN QString & | operator+= (const QByteArray &s) |
iterator | begin () |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first character in the string. | |
const_iterator | begin () const |
const_iterator | cbegin () const |
const_iterator | constBegin () const |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the string. | |
iterator | end () |
Returns an \l{STL-style iterators}{STL-style iterator} pointing just after the last character in the string. | |
const_iterator | end () const |
const_iterator | cend () const |
const_iterator | constEnd () const |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing just after the last character in the string. | |
reverse_iterator | rbegin () |
reverse_iterator | rend () |
const_reverse_iterator | rbegin () const |
const_reverse_iterator | rend () const |
const_reverse_iterator | crbegin () const |
const_reverse_iterator | crend () const |
void | push_back (QChar c) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Appends the given ch character onto the end of this string. | |
void | push_back (const QString &s) |
This function is provided for STL compatibility, appending the given other string onto the end of this string. | |
void | push_front (QChar c) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Prepends the given ch character to the beginning of this string. | |
void | push_front (const QString &s) |
This function is provided for STL compatibility, prepending the given other string to the beginning of this string. | |
void | shrink_to_fit () |
iterator | erase (const_iterator first, const_iterator last) |
iterator | erase (const_iterator it) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
constexpr qsizetype | max_size () const noexcept |
std::string | toStdString () const |
Returns a std::string object with the data contained in this QString. | |
std::wstring | toStdWString () const |
Returns a std::wstring object with the data contained in this QString. | |
std::u16string | toStdU16String () const |
std::u32string | toStdU32String () const |
Q_IMPLICIT | operator std::u16string_view () const noexcept |
constexpr bool | isNull () const |
Returns true if this string is null; otherwise returns false . | |
bool | isRightToLeft () const |
Returns true if the string is read right to left. | |
bool | isValidUtf16 () const noexcept |
QString (qsizetype size, Qt::Initialization) | |
QString (DataPointer &&dd) | |
DataPointer & | data_ptr () |
const DataPointer & | data_ptr () const |
Static Public Member Functions | |
static constexpr qsizetype | maxSize () noexcept |
static QString | vasprintf (const char *format, va_list ap) Q_ATTRIBUTE_FORMAT_PRINTF(1 |
static QString static QString | asprintf (const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1 |
static QString | fromLatin1 (QByteArrayView ba) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static Q_WEAK_OVERLOAD QString | fromLatin1 (const QByteArray &ba) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static QString | fromLatin1 (const char *str, qsizetype size) |
Returns a QString initialized with the first size characters of the Latin-1 string str. | |
static QString | fromUtf8 (QByteArrayView utf8) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static Q_WEAK_OVERLOAD QString | fromUtf8 (const QByteArray &ba) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static QString | fromUtf8 (const char *utf8, qsizetype size) |
Returns a QString initialized with the first size bytes of the UTF-8 string str. | |
static QString | fromLocal8Bit (QByteArrayView ba) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static Q_WEAK_OVERLOAD QString | fromLocal8Bit (const QByteArray &ba) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static QString | fromLocal8Bit (const char *str, qsizetype size) |
Returns a QString initialized with the first size characters of the 8-bit string str. | |
static QString | fromUtf16 (const char16_t *, qsizetype size=-1) |
static QString | fromUcs4 (const char32_t *, qsizetype size=-1) |
static QString | fromRawData (const char16_t *unicode, qsizetype size) |
static QString | fromRawData (const QChar *, qsizetype size) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static QString | fromWCharArray (const wchar_t *string, qsizetype size=-1) |
static int | compare (const QString &s1, const QString &s2, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept |
static int | compare (const QString &s1, QLatin1StringView s2, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept |
static int | compare (QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept |
static int | compare (const QString &s1, QStringView s2, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept |
static int | compare (QStringView s1, const QString &s2, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept |
static int | localeAwareCompare (const QString &s1, const QString &s2) |
Compares s1 with s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2. | |
static int | localeAwareCompare (QStringView s1, QStringView s2) |
static QString | number (int, int base=10) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static QString | number (uint, int base=10) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static QString | number (long, int base=10) |
Returns a string equivalent of the number n according to the specified base. | |
static QString | number (ulong, int base=10) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static QString | number (qlonglong, int base=10) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static QString | number (qulonglong, int base=10) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static QString | number (double, char format='g', int precision=6) |
Returns a string representing the floating-point number n. | |
static QString | fromStdString (const std::string &s) |
static QString | fromStdWString (const std::wstring &s) |
Returns a copy of the str string. | |
static QString | fromStdU16String (const std::u16string &s) |
static QString | fromStdU32String (const std::u32string &s) |
Public Attributes | |
static QString static QString qsizetype | from = 0 |
static QString static QString qsizetype Qt::CaseSensitivity | cs = Qt::CaseSensitive) const |
qsizetype | from |
qsizetype Qt::CaseSensitivity | cs = Qt::CaseSensitive) const |
Related Symbols | |
(Note that these are not member symbols.) | |
QString | operator+ (QString &&s1, const QString &s2) |
Returns a string which is the result of concatenating s1 and s2. | |
QString | operator+ (const QString &s1, const char *s2) |
Returns a string which is the result of concatenating s1 and s2 (s2 is converted to Unicode using the QString::fromUtf8() function). | |
QString | operator+ (const char *s1, const QString &s2) |
Returns a string which is the result of concatenating s1 and s2 (s1 is converted to Unicode using the QString::fromUtf8() function). | |
QString | operator+ (const QString &lhs, QStringView rhs) |
QDataStream & | operator<< (QDataStream &stream, const QString &string) |
Writes the given string to the specified stream. | |
QDataStream & | operator>> (QDataStream &stream, QString &string) |
Reads a string from the specified stream into the given string. | |
operator""_s (const char16_t *str, size_t size) | |
\macro QStringLiteral(str) | |
typedef const QChar* QString::const_iterator |
typedef const QChar* QString::const_pointer |
The QString::const_pointer typedef provides an STL-style const pointer to a QString element (QChar).
typedef const QChar& QString::const_reference |
typedef std::reverse_iterator<const_iterator> QString::const_reverse_iterator |
typedef const_iterator QString::ConstIterator |
\macro QT_RESTRICTED_CAST_FROM_ASCII
Disables most automatic conversions from source literals and 8-bit data to unicode QStrings, but allows the use of the {QChar(char)} and
{QString(const char (&ch)[N]} constructors, and the
{QString::operator=(const char (&ch)[N])} assignment operator. This gives most of the type-safety benefits of \l QT_NO_CAST_FROM_ASCII but does not require user code to wrap character and string literals with QLatin1Char, QLatin1StringView or similar.
Using this macro together with source strings outside the 7-bit range, non-literals, or literals with embedded NUL characters is undefined.
\macro QT_NO_CAST_FROM_ASCII
Disables automatic conversions from 8-bit strings ({char *}) to Unicode QStrings, as well as from 8-bit
{char} types (
{char} and
{unsigned char}) to QChar.
\macro QT_NO_CAST_TO_ASCII
Disables automatic conversion from QString to 8-bit strings ({char *}).
\macro QT_ASCII_CAST_WARNINGS
This macro can be defined to force a warning whenever a function is called that automatically converts between unicode and 8-bit encodings.
Note: This only works for compilers that support warnings for deprecated API.
\class QString \inmodule QtCore \reentrant \brief The QString class provides a Unicode character string. \ingroup tools \ingroup shared \ingroup string-processing \compares strong \compareswith strong QChar QLatin1StringView {const char16_t *} \ QStringView QUtf8StringView \endcompareswith \compareswith strong QByteArray QByteArrayView {const char *} When comparing with byte arrays, their content is interpreted as UTF-8. \endcompareswith QString stores a string of 16-bit \l{QChar}s, where each QChar corresponds to one UTF-16 code unit. (Unicode characters with code values above 65535 are stored using surrogate pairs, that is, two consecutive \l{QChar}s.) \l{Unicode} is an international standard that supports most of the writing systems in use today. It is a superset of US-ASCII (ANSI X3.4-1986) and Latin-1 (ISO 8859-1), and all the US-ASCII/Latin-1 characters are available at the same code positions. Behind the scenes, QString uses \l{implicit sharing} (copy-on-write) to reduce memory usage and to avoid the needless copying of data. This also helps reduce the inherent overhead of storing 16-bit characters instead of 8-bit characters. In addition to QString, Qt also provides the QByteArray class to store raw bytes and traditional 8-bit '\\0'-terminated strings. For most purposes, QString is the class you want to use. It is used throughout the Qt API, and the Unicode support ensures that your applications are easy to translate if you want to expand your application's market at some point. Two prominent cases where QByteArray is appropriate are when you need to store raw binary data, and when memory conservation is critical (like in embedded systems). \section1 Initializing a string One way to initialize a QString is to pass a \c{const char
} to its constructor. For example, the following code creates a QString of size 5 containing the data "Hello":
QString converts the {const char *} data into Unicode using the fromUtf8() function.
In all of the QString functions that take {const char *} parameters, the
{const char *} is interpreted as a classic C-style
{'\0'}-terminated string. Except where the function's name overtly indicates some other encoding, such
{const char *} parameters are assumed to be encoded in UTF-8.
You can also provide string data as an array of \l{QChar}s:
QString makes a deep copy of the QChar data, so you can modify it later without experiencing side effects. You can avoid taking a deep copy of the character data by using QStringView or QString::fromRawData() instead.
Another approach is to set the size of the string using resize() and to initialize the data character per character. QString uses 0-based indexes, just like C++ arrays. To access the character at a particular index position, you can use \l operator[](). On non-{const} strings, \l operator[]() returns a reference to a character that can be used on the left side of an assignment. For example:
For read-only access, an alternative syntax is to use the at() function:
The at() function can be faster than \l operator[]() because it never causes a \l{deep copy} to occur. Alternatively, use the first(), last(), or sliced() functions to extract several characters at a time.
A QString can embed '\0' characters (QChar::Null). The size() function always returns the size of the whole string, including embedded '\0' characters.
After a call to the resize() function, newly allocated characters have undefined values. To set all the characters in the string to a particular value, use the fill() function.
QString provides dozens of overloads designed to simplify string usage. For example, if you want to compare a QString with a string literal, you can write code like this and it will work as expected:
You can also pass string literals to functions that take QStrings as arguments, invoking the QString(const char *) constructor. Similarly, you can pass a QString to a function that takes a {const char *} argument using the \l qPrintable() macro, which returns the given QString as a
{const char *}. This is equivalent to calling <QString>.toLocal8Bit().constData().
QString provides the following basic functions for modifying the character data: append(), prepend(), insert(), replace(), and remove(). For example:
In the above example, the replace() function's first two arguments are the position from which to start replacing and the number of characters that should be replaced.
When data-modifying functions increase the size of the string, QString may reallocate the memory in which it holds its data. When this happens, QString expands by more than it immediately needs so as to have space for further expansion without reallocation until the size of the string has significantly increased.
The insert(), remove(), and, when replacing a sub-string with one of different size, replace() functions can be slow (\l{linear time}) for large strings because they require moving many characters in the string by at least one position in memory.
If you are building a QString gradually and know in advance approximately how many characters the QString will contain, you can call reserve(), asking QString to preallocate a certain amount of memory. You can also call capacity() to find out how much memory the QString actually has allocated.
QString provides \l{STL-style iterators} (QString::const_iterator and QString::iterator). In practice, iterators are handy when working with generic algorithms provided by the C++ standard library.
{const} method of the QString is called. Accessing such an iterator or reference after the call to a non-
{const} method leads to undefined behavior. When stability for iterator-like functionality is required, you should use indexes instead of iterators, as they are not tied to QString's internal state and thus do not get invalidated.
{const} operator or function used on a given QString may cause it to internally perform a deep copy of its data. This invalidates all iterators over the string and references to individual characters within it. Do not call non-const functions while keeping iterators. Accessing an iterator or reference after it has been invalidated leads to undefined behavior. See the \l{Implicit sharing iterator problem} section for more information.A frequent requirement is to remove or simplify the spacing between visible characters in a string. The characters that make up that spacing are those for which \l {QChar::}{isSpace()} returns true
, such as the simple space {' '}, the horizontal tab
{'\t'} and the newline
{'\n'}. To obtain a copy of a string leaving out any spacing from its start and end, use \l trimmed(). To also replace each sequence of spacing characters within the string with a simple space,
{' '}, use \l simplified().
If you want to find all occurrences of a particular character or substring in a QString, use the indexOf() or lastIndexOf() functions.The former searches forward, the latter searches backward. Either can be told an index position from which to start their search. Each returns the index position of the character or substring if they find it; otherwise, they return -1. For example, here is a typical loop that finds all occurrences of a particular substring:
QString provides many functions for converting numbers into strings and strings into numbers. See the arg() functions, the setNum() functions, the number() static functions, and the toInt(), toDouble(), and similar functions.
To get an uppercase or lowercase version of a string, use toUpper() or toLower().
Lists of strings are handled by the QStringList class. You can split a string into a list of strings using the split() function, and join a list of strings into a single string with an optional separator using QStringList::join(). You can obtain a filtered list from a string list by selecting the entries in it that contain a particular substring or match a particular QRegularExpression. See QStringList::filter() for details.
To see if a QString starts or ends with a particular substring, use startsWith() or endsWith(). To check whether a QString contains a specific character or substring, use the contains() function. To find out how many times a particular character or substring occurs in a string, use count().
To obtain a pointer to the actual character data, call data() or constData(). These functions return a pointer to the beginning of the QChar data. The pointer is guaranteed to remain valid until a non-{const} function is called on the QString.
QStrings can be compared using overloaded operators such as \l operator<(), \l operator<=(), \l operator==(), \l operator>=(), and so on. The comparison is based exclusively on the lexicographical order of the two strings, seen as sequences of UTF-16 code units. It is very fast but is not what a human would expect; the QString::localeAwareCompare() function is usually a better choice for sorting user-interface strings, when such a comparison is available.
When Qt is linked with the ICU library (which it usually is), its locale-aware sorting is used. Otherwise, platform-specific solutions are used: \list
strcoll()
. \endlistQString provides the following functions that return a {const char *} version of the string as QByteArray: toUtf8(), toLatin1(), and toLocal8Bit().
\list
To convert from one of these encodings, QString provides fromLatin1(), fromUtf8(), and fromLocal8Bit(). Other encodings are supported through the QStringEncoder and QStringDecoder classes.
As mentioned above, QString provides a lot of functions and operators that make it easy to interoperate with {const char *} strings. But this functionality is a double-edged sword: It makes QString more convenient to use if all strings are US-ASCII or Latin-1, but there is always the risk that an implicit conversion from or to
{const char *} is done using the wrong 8-bit encoding. To minimize these risks, you can turn off these implicit conversions by defining some of the following preprocessor symbols:
\list
You then need to explicitly call fromUtf8(), fromLatin1(), or fromLocal8Bit() to construct a QString from an 8-bit string, or use the lightweight QLatin1StringView class. For example:
Similarly, you must call toLatin1(), toUtf8(), or toLocal8Bit() explicitly to convert the QString to an 8-bit string.
\table 100 % \header
\row
{int}s or other basic types. For example:The result
variable is a normal variable allocated on the stack. When return
is called, and because we're returning by value, the copy constructor is called and a copy of the string is returned. No actual copying takes place thanks to the implicit sharing.
\endtable
For historical reasons, QString distinguishes between null and empty strings. A null string is a string that is initialized using QString's default constructor or by passing \nullptr to the constructor. An empty string is any string with size 0. A null string is always empty, but an empty string isn't necessarily null:
All functions except isNull() treat null strings the same as empty strings. For example, toUtf8().constData() returns a valid pointer (not \nullptr) to a '\0' character for a null string. We recommend that you always use the isEmpty() function and avoid isNull().
When a QString::arg() {''} format specifier includes the
{'L'} locale qualifier, and the base is ten (its default), the default locale is used. This can be set using \l{QLocale::setDefault()}. For more refined control of localized string representations of numbers, see QLocale::toString(). All other number formatting done by QString follows the C locale's representation of numbers.
When QString::arg() applies left-padding to numbers, the fill character {'0'} is treated specially. If the number is negative, its minus sign appears before the zero-padding. If the field is localized, the locale-appropriate zero character is used in place of
{'0'}. For floating-point numbers, this special treatment only applies if the number is finite.
In member functions (for example, arg() and number()) that format floating-point numbers (float
or double
) as strings, the representation used can be controlled by a choice of format and precision, whose meanings are as for \l {QLocale::toString(double, char, int)}.
If the selected format includes an exponent, localized forms follow the locale's convention on digits in the exponent. For non-localized formatting, the exponent shows its sign and includes at least two digits, left-padding with zero if needed.
Many strings are known at compile time. The QString constructor from C++ string literals will copy the contents of the string, treating the contents as UTF-8. This requires memory allocation and re-encoding string data, operations that will happen at runtime. If the string data is known at compile time, you can use the QStringLiteral macro or similarly {operator""_s} to create QString's payload at compile time instead.
Using the QString {'+'} operator, it is easy to construct a complex string from multiple substrings. You will often write code like this:
There is nothing wrong with either of these string constructions, but there are a few hidden inefficiencies:
First, repeated use of the {'+'} operator may lead to multiple memory allocations. When concatenating {n} substrings, where {n > 2}, there can be as many as {n - 1} calls to the memory allocator.
These allocations can be optimized by an internal class {QStringBuilder}. This class is marked internal and does not appear in the documentation, because you aren't meant to instantiate it in your code. Its use will be automatic, as described below.
{QStringBuilder} uses expression templates and reimplements the
{''} operator so that when you use
{''} for string concatenation instead of
{'+'}, multiple substring concatenations will be postponed until the final result is about to be assigned to a QString. At this point, the amount of memory required for the final result is known. The memory allocator is then called {once} to get the required space, and the substrings are copied into it one by one.
Additional efficiency is gained by inlining and reducing reference counting (the QString created from a {QStringBuilder} has a ref count of 1, whereas QString::append() needs an extra test).
There are two ways you can access this improved method of string construction. The straightforward way is to include {QStringBuilder} wherever you want to use it and use the
{''} operator instead of
{'+'} when concatenating strings:
A more global approach, which is more convenient but not entirely source-compatible, is to define QT_USE_QSTRINGBUILDER
(by adding it to the compiler flags) at build time. This will make concatenating strings with {'+'} work the same way as
{QStringBuilder's}
{''}.
auto
keyword) with the result of string concatenation when QStringBuilder is enabled will show that the concatenation is indeed an object of a QStringBuilder specialization:This does not cause any harm, as QStringBuilder will implicitly convert to QString when required. If this is undesirable, then one should specify the necessary types instead of having the compiler deduce them:
The maximum size of QString depends on the architecture. Most 64-bit systems can allocate more than 2 GB of memory, with a typical limit of 2^63 bytes. The actual value also depends on the overhead required for managing the data block. As a result, you can expect a maximum size of 2 GB minus overhead on 32-bit platforms and 2^63 bytes minus overhead on 64-bit platforms. The number of elements that can be stored in a QString is this maximum size divided by the size of QChar.
When memory allocation fails, QString throws a std::bad_alloc
exception if the application was compiled with exception support. Out-of-memory conditions in Qt containers are the only cases where Qt will throw exceptions. If exceptions are disabled, then running out of memory is undefined behavior.
Qt-style synonym for QString::const_iterator.
typedef QStringPrivate QString::DataPointer |
typedef qptrdiff QString::difference_type |
typedef iterator QString::Iterator |
Qt-style synonym for QString::iterator.
typedef QChar* QString::iterator |
typedef QChar* QString::pointer |
The QString::pointer typedef provides an STL-style pointer to a QString element (QChar).
typedef QChar& QString::reference |
typedef std::reverse_iterator<iterator> QString::reverse_iterator |
typedef qsizetype QString::size_type |
typedef QChar QString::value_type |
This enum describes the various normalized forms of Unicode text.
\value NormalizationForm_D Canonical Decomposition \value NormalizationForm_C Canonical Decomposition followed by Canonical Composition \value NormalizationForm_KD Compatibility Decomposition \value NormalizationForm_KC Compatibility Decomposition followed by Canonical Composition
Enumerator | |
---|---|
NormalizationForm_D | |
NormalizationForm_C | |
NormalizationForm_KD | |
NormalizationForm_KC |
enum QString::SectionFlag |
This enum specifies flags that can be used to affect various aspects of the section() function's behavior with respect to separators and empty fields.
\value SectionDefault Empty fields are counted, leading and trailing separators are not included, and the separator is compared case sensitively.
\value SectionSkipEmpty Treat empty fields as if they don't exist, i.e. they are not considered as far as start and end are concerned.
\value SectionIncludeLeadingSep Include the leading separator (if any) in the result string.
\value SectionIncludeTrailingSep Include the trailing separator (if any) in the result string.
\value SectionCaseInsensitiveSeps Compare the separator case-insensitively.
Enumerator | |
---|---|
SectionDefault | |
SectionSkipEmpty | |
SectionIncludeLeadingSep | |
SectionIncludeTrailingSep | |
SectionCaseInsensitiveSeps |
|
constexprnoexcept |
Constructs a string initialized with the first size characters of the QChar array unicode.
If unicode is 0, a null string is constructed.
If size is negative, unicode is assumed to point to a '\0'-terminated array and its length is determined dynamically. The terminating null character is not considered part of the string.
QString makes a deep copy of the string data. The unicode data is copied as is and the Byte Order Mark is preserved if present.
Definition at line 2487 of file qstring.cpp.
QString::QString | ( | QChar | c | ) |
Constructs a string of size 1 containing the character ch.
Definition at line 2553 of file qstring.cpp.
Constructs a string of the given size with every character set to ch.
Definition at line 2511 of file qstring.cpp.
|
inline |
Constructs a copy of the Latin-1 string viewed by str.
|
inlineexplicit |
|
inlinenoexcept |
Constructs a copy of other.
This operation takes \l{constant time}, because QString is \l{implicitly shared}. This makes returning a QString from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes \l{linear time}.
|
inlinedefaultnoexcept |
Move-constructs a QString instance, making it point at the same object that other was pointing to.
|
inline |
Constructs a string initialized with the 8-bit string str.
The given const char pointer is converted to Unicode using the fromUtf8() function.
You can disable this constructor by defining \l QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.
{QString(const char (&ch)[N])} constructor instead. Using non-literal input, or input with embedded NUL characters, or non-7-bit characters is undefined in this case.
|
inline |
Constructs a string initialized with the byte array ba.
The given byte array is converted to Unicode using fromUtf8().
You can disable this constructor by defining \l QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.
QString::QString | ( | qsizetype | size, |
Qt::Initialization | ) |
Constructs a string of the given size without initializing the characters. This is only used in QStringBuilder::toString()
.
Definition at line 2532 of file qstring.cpp.
|
inlineexplicit |
|
inline |
|
inline |
Definition at line 3178 of file qstring.cpp.
Appends the string str onto the end of this string.
Example:
This is the same as using the insert() function:
The append() function is typically very fast (\l{constant time}), because QString preallocates extra space at the end of the string data so it can grow without reallocating the entire string each time.
Definition at line 3149 of file qstring.cpp.
Definition at line 3244 of file qstring.cpp.
QString & QString::append | ( | QLatin1StringView | s | ) |
Definition at line 3195 of file qstring.cpp.
|
inline |
QString & QString::append | ( | QUtf8StringView | s | ) |
Definition at line 3207 of file qstring.cpp.
|
inlinenodiscard |
Returns a copy of this string with the lowest-numbered place-marker replaced by string a, i.e., %1
, %2
, ..., %99
.
fieldWidth specifies the minimum amount of space that a shall occupy. If a requires less space than fieldWidth, it is padded to fieldWidth with character fillChar. A positive fieldWidth produces right-aligned text. A negative fieldWidth produces left-aligned text.
This example shows how we might create a status
string for reporting progress while processing a list of files:
First, arg(i)
replaces %1
. Then arg(total)
replaces %2
. Finally, arg(fileName)
replaces %3
.
One advantage of using arg() over asprintf() is that the order of the numbered place markers can change, if the application's strings are translated into other languages, but each arg() will still replace the lowest-numbered unreplaced place-marker, no matter where it appears. Also, if place-marker i
appears more than once in the string, arg() replaces all of them.
If there is no unreplaced place-marker remaining, a warning message is printed and the result is undefined. Place-marker numbers must be in the range 1 to 99.
{char}, QChar, QString, QStringView, and QLatin1StringView and in some cases,
{wchar_t} and
{char16_t} arguments would resolve to the integer overloads. In Qt versions prior to 5.10, this function lacked the QStringView and QLatin1StringView overloads.
|
static |
Safely builds a formatted string from the format string cformat and an arbitrary list of arguments.
The format string supports the conversion specifiers, length modifiers, and flags provided by printf() in the standard C++ library. The cformat string and {s} arguments must be UTF-8 encoded.
{lc} escape sequence expects a unicode character of type char16_t
, or ushort
(as returned by QChar::unicode()). The
{ls} escape sequence expects a pointer to a zero-terminated array of unicode characters of type char16_t
, or ushort (as returned by QString::utf16()). This is at odds with the printf() in the standard C++ library, which defines {lc}
to print a wchar_t and
{ls} to print a
{wchar_t*}, and might also produce compiler warnings on platforms where the size of {wchar_t}
is not 16 bits.For \l {QObject::tr()}{translations}, especially if the strings contains more than one escape sequence, you should consider using the arg() function instead. This allows the order of the replacements to be controlled by the translator.
Definition at line 7350 of file qstring.cpp.
|
inline |
QString & QString::assign | ( | QAnyStringView | v | ) |
Replaces the contents of this string with a copy of v and returns a reference to this string.
The size of this string will be equal to the size of v, converted to UTF-16 as if by {v.toString()}. Unlike QAnyStringView::toString(), however, this function only allocates memory if the estimated size exceeds the capacity of this string or this string is shared.
Definition at line 3398 of file qstring.cpp.
Replaces the contents of this string with n copies of c and returns a reference to this string.
The size of this string will be equal to n, which has to be non-negative.
This function will only allocate memory if n exceeds the capacity of this string or this string is shared.
Returns the character at the given index position in the string.
The position must be a valid index position in the string (i.e., 0 <= position < size()).
|
inlinenodiscard |
Returns a reference to the last character in the string. Same as {operator[](size() - 1)}.
This function is provided for STL compatibility.
|
inlinenodiscard |
|
inline |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first character in the string.
! [iterator-invalidation-func-desc]
\sa constBegin(), end()
|
inline |
|
inline |
Returns the maximum number of characters that can be stored in the string without forcing a reallocation.
The sole purpose of this function is to provide a means of fine tuning QString's memory usage. In general, you will rarely ever need to call this function. If you want to know how many characters are in the string, call size().
|
inline |
|
inline |
Removes n characters from the end of the string.
If n is greater than or equal to size(), the result is an empty string; if n is negative, it is equivalent to passing zero.
Example:
If you want to remove characters from the beginning of the string, use remove() instead.
Definition at line 6389 of file qstring.cpp.
|
inline |
|
noexcept |
Definition at line 6723 of file qstring.cpp.
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinenoexcept |
|
noexcept |
Definition at line 6748 of file qstring.cpp.
|
inlinestaticnoexcept |
|
inlinenoexcept |
|
inlinestaticnoexcept |
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the string.
iterator-invalidation-func-desc
|
inline |
Returns a pointer to the data stored in the QString.
The pointer can be used to access the characters that compose the string.
Note that the pointer remains valid only as long as the string is not modified.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing just after the last character in the string.
iterator-invalidation-func-desc
|
inlinenodiscard |
Returns true
if this string contains an occurrence of the string str; otherwise returns false
.
{search-comparison-case-sensitivity} {search}
Example:
|
inlinenodiscard |
|
inlinenodiscard |
|
inlinenodiscardnoexcept |
|
nodiscard |
Returns the number of (potentially overlapping) occurrences of the string str in this string.
{search-comparison-case-sensitivity} {search}
Definition at line 4826 of file qstring.cpp.
|
nodiscard |
Definition at line 4841 of file qstring.cpp.
|
nodiscard |
Definition at line 4856 of file qstring.cpp.
|
inline |
|
inline |
|
inline |
Returns a pointer to the data stored in the QString.
The pointer can be used to access and modify the characters that compose the string.
Unlike constData() and unicode(), the returned data is always '\0'-terminated.
Example:
Note that the pointer remains valid only as long as the string is not modified by other means. For read-only access, constData() is faster because it never causes a \l{deep copy} to occur.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
|
inline |
|
inline |
Returns an \l{STL-style iterators}{STL-style iterator} pointing just after the last character in the string.
iterator-invalidation-func-desc
|
inline |
bool QString::endsWith | ( | const QString & | s, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) const |
Returns true
if the string ends with s; otherwise returns false
.
{search-comparison-case-sensitivity} {search}
Definition at line 5519 of file qstring.cpp.
bool QString::endsWith | ( | QChar | c, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) const |
Definition at line 5550 of file qstring.cpp.
bool QString::endsWith | ( | QLatin1StringView | s, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) const |
Definition at line 5539 of file qstring.cpp.
|
inlinenodiscardnoexcept |
QString::iterator QString::erase | ( | QString::const_iterator | first, |
QString::const_iterator | last ) |
Removes from the string the characters in the half-open range [ first , last ). Returns an iterator to the character immediately after the last erased character (i.e. the character referred to by last before the erase).
Definition at line 9331 of file qstring.cpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Removes the character denoted by it
from the string. Returns an iterator to the character immediately after the erased character.
Returns a QString initialized with the first size characters of the Latin-1 string str.
If size is {-1},
{strlen(str)} is used instead.
|
inlinestatic |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QString initialized with the Latin-1 string str.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QString initialized with the Latin-1 string str.
Definition at line 5904 of file qstring.cpp.
Returns a QString initialized with the first size characters of the 8-bit string str.
If size is {-1},
{strlen(str)} is used instead.
{qstring-local-8-bit-equivalent} {fromUtf8}
|
inlinestatic |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QString initialized with the 8-bit string str.
{qstring-local-8-bit-equivalent} {fromUtf8}
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QString initialized with the 8-bit string str.
{qstring-local-8-bit-equivalent} {fromUtf8}
Definition at line 5982 of file qstring.cpp.
Constructs a QString that uses the first size Unicode characters in the array unicode. The data in unicode is not copied. The caller must be able to guarantee that unicode will not be deleted or modified as long as the QString (or an unmodified copy of it) exists.
Any attempts to modify the QString or copies of it will cause it to create a deep copy of the data, ensuring that the raw data isn't modified.
Here is an example of how we can use a QRegularExpression on raw data in memory without requiring to copy the data into a QString:
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inlinestatic |
{from-std-string} {UTF-8} {fromUtf8()}
|
inlinestatic |
{from-std-string} {UTF-16} {fromUtf16()}
|
inlinestatic |
{from-std-string} {UTF-32} {fromUcs4()}
|
inlinestatic |
Returns a copy of the str string.
The given string is assumed to be encoded in utf16 if the size of wchar_t is 2 bytes (e.g. on windows) and ucs4 if the size of wchar_t is 4 bytes (most Unix systems).
char32_t
overload instead. Returns a QString initialized with the first size characters of the Unicode string unicode (encoded as UTF-32).
If size is -1 (default), unicode must be '\0'-terminated.
char32_t
overload instead. Definition at line 6110 of file qstring.cpp.
If size is -1 (default), unicode must be '\0'-terminated.
This function checks for a Byte Order Mark (BOM). If it is missing, host byte order is assumed.
This function is slow compared to the other Unicode conversions. Use QString(const QChar *, qsizetype) or QString(const QChar *) if possible.
QString makes a deep copy of the Unicode data.
char16_t
overload instead. char16_t
overload instead. Definition at line 6078 of file qstring.cpp.
Returns a QString initialized with the first size bytes of the UTF-8 string str.
If size is {-1},
{strlen(str)} is used instead.
UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QString. However, invalid sequences are possible with UTF-8 and, if any such are found, they will be replaced with one or more "replacement characters", or suppressed. These include non-Unicode sequences, non-characters, overlong sequences or surrogate codepoints encoded into UTF-8.
This function can be used to process incoming data incrementally as long as all UTF-8 characters are terminated within the incoming data. Any unterminated characters at the end of the string will be replaced or suppressed. In order to do stateful decoding, please use \l QStringDecoder.
|
inlinestatic |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QString initialized with the UTF-8 string str.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QString initialized with the UTF-8 string str.
Definition at line 6051 of file qstring.cpp.
|
inlinestaticnodiscard |
Reads the first size code units of the wchar_t
array to whose start string points, converting them to Unicode and returning the result as a QString. The encoding used by wchar_t
is assumed to be UTF-32 if the type's size is four bytes or UTF-16 if its size is two bytes.
If size is -1 (default), the string must be '\0'-terminated.
|
inlinenodiscard |
Returns a reference to the first character in the string. Same as {operator[](0)}.
This function is provided for STL compatibility.
|
inlinenodiscard |
|
nodiscard |
{qstring-first-index-of} {string} {str}
{search-comparison-case-sensitivity} {search}
Example:
negative-index-start-search-from-end
Definition at line 4490 of file qstring.cpp.
|
nodiscard |
} {qstring-first-index-of} {Latin-1 string viewed by} {str}
{search-comparison-case-sensitivity} {search}
Example:
negative-index-start-search-from-end
Definition at line 4525 of file qstring.cpp.
|
inlinenodiscardnoexcept |
|
inline |
|
inline |
Definition at line 3097 of file qstring.cpp.
Definition at line 3124 of file qstring.cpp.
Definition at line 3017 of file qstring.cpp.
|
inline |
QString & QString::insert | ( | qsizetype | i, |
QUtf8StringView | s ) |
Definition at line 3040 of file qstring.cpp.
|
inlineconstexprnoexcept |
bool QString::isLower | ( | ) | const |
Returns true
if the string is lowercase, that is, it's identical to its toLower() folding.
Note that this does not mean that the string does not contain uppercase letters (some uppercase letters do not have a lowercase folding; they are left unchanged by toLower()). For more information, refer to the Unicode standard, section 3.13.
Definition at line 5611 of file qstring.cpp.
|
inlineconstexpr |
Returns true
if this string is null; otherwise returns false
.
Example:
Qt makes a distinction between null strings and empty strings for historical reasons. For most applications, what matters is whether or not a string contains any data, and this can be determined using the isEmpty() function.
bool QString::isRightToLeft | ( | ) | const |
Returns true
if the string is read right to left.
Definition at line 9227 of file qstring.cpp.
|
inline |
bool QString::isUpper | ( | ) | const |
Returns true
if the string is uppercase, that is, it's identical to its toUpper() folding.
Note that this does not mean that the string does not contain lowercase letters (some lowercase letters do not have a uppercase folding; they are left unchanged by toUpper()). For more information, refer to the Unicode standard, section 3.13.
Definition at line 5593 of file qstring.cpp.
|
inlinenodiscardnoexcept |
Returns true
if the string contains valid UTF-16 encoded data, or false
otherwise.
Note that this function does not perform any special validation of the data; it merely checks if it can be successfully decoded from UTF-16. The data is assumed to be in host byte order; the presence of a BOM is meaningless.
|
nodiscard |
{qstring-last-index-of} {string} {str}
negative-index-start-search-from-end
Returns -1 if str is not found.
{search-comparison-case-sensitivity} {search}
Example:
{-1} is normally thought of as searching from the end of the string: the match at the end is after the last character, so it is excluded. To include such a final empty match, either give a positive value for from or omit the from parameter entirely.Definition at line 4559 of file qstring.cpp.
|
inlinenodiscard |
|
inlinenodiscardnoexcept |
|
nodiscard |
Definition at line 4607 of file qstring.cpp.
|
inlinenodiscard |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
nodiscard |
Returns a string of size width that contains this string padded by the fill character.
If truncate is false
and the size() of the string is more than width, then the returned string is a copy of the string.
If truncate is true
and the size() of the string is more than width, then any characters in a copy of the string after position width are removed, and the copy is returned.
Definition at line 7106 of file qstring.cpp.
|
inlineconstexprnoexcept |
int QString::localeAwareCompare | ( | const QString & | s | ) | const |
Definition at line 6966 of file qstring.cpp.
Compares s1 with s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.
The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.
|
inline |
|
inlinestatic |
|
inlineconstexprnoexcept |
|
inlinestaticconstexprnoexcept |
Definition at line 5328 of file qstring.cpp.
Definition at line 5310 of file qstring.cpp.
|
nodiscard |
Returns the string in the given Unicode normalization mode, according to the given version of the Unicode standard.
Definition at line 8562 of file qstring.cpp.
|
inline |
If this string data isn't null-terminated, this method will make a deep copy of the data and make it null-terminated.
A QString is null-terminated by default, however in some cases (e.g. when using fromRawData()), the string data doesn't necessarily end with a {\0}
character, which could be a problem when calling methods that expect a null-terminated string.
|
inlinenodiscard |
Returns a string representing the floating-point number n.
Returns a string that represents n, formatted according to the specified format and precision.
For formats with an exponent, the exponent will show its sign and have at least two digits, left-padding the exponent with zero if needed.
Definition at line 8229 of file qstring.cpp.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 8171 of file qstring.cpp.
|
static |
Returns a string equivalent of the number n according to the specified base.
The base is 10 by default and must be between 2 and 36. For bases other than 10, n is treated as an unsigned integer.
The formatting always uses QLocale::C, i.e., English/UnitedStates. To get a localized string representation of a number, use QLocale::toString() with the appropriate locale.
Definition at line 8153 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 8187 of file qstring.cpp.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 8206 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 8179 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 8163 of file qstring.cpp.
|
inlinenoexcept |
|
inline |
|
inline |
Appends the string other onto the end of this string and returns a reference to this string.
Example:
This operation is typically very fast (\l{constant time}), because QString preallocates extra space at the end of the string data so it can grow without reallocating the entire string each time.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Assigns other to this string and returns a reference to this string.
Definition at line 2829 of file qstring.cpp.
Definition at line 2893 of file qstring.cpp.
QString & QString::operator= | ( | QLatin1StringView | latin1 | ) |
Definition at line 2849 of file qstring.cpp.
|
inline |
|
inline |
Prepends the string str to the beginning of this string and returns a reference to this string.
This operation is typically very fast (\l{constant time}), because QString preallocates extra space at the beginning of the string data, so it can grow without reallocating the entire string each time.
Example:
|
inline |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Appends the given ch character onto the end of this string.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Prepends the given ch character to the beginning of this string.
|
nodiscard |
|
inline |
|
inline |
QString & QString::remove | ( | const QString & | str, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) |
Removes every occurrence of the given str string in this string, and returns a reference to this string.
{search-comparison-case-sensitivity} {search}
This is the same as replace
(str, "", cs).
shrinking-erase
Definition at line 3539 of file qstring.cpp.
QString & QString::remove | ( | QChar | ch, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) |
Removes every occurrence of the character ch in this string, and returns a reference to this string.
{search-comparison-case-sensitivity} {search}
Example:
This is the same as replace
(ch, "", cs).
shrinking-erase
Definition at line 3619 of file qstring.cpp.
QString & QString::remove | ( | QLatin1StringView | str, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) |
Removes every occurrence of the given Latin-1 string viewed by str from this string, and returns a reference to this string.
{search-comparison-case-sensitivity} {search}
This is the same as replace
(str, "", cs).
shrinking-erase
Definition at line 3564 of file qstring.cpp.
Removes n characters from the string, starting at the given position index, and returns a reference to the string.
If the specified position index is within the string, but position + n is beyond the end of the string, the string is truncated at the specified position.
If n is <= 0 nothing is changed.
! [shrinking-erase] Element removal will preserve the string's capacity and not reduce the amount of allocated memory. To shed extra capacity and free as much memory as possible, call squeeze() after the last change to the string's size. ! [shrinking-erase]
Definition at line 3458 of file qstring.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Returns a copy of this string repeated the specified number of times.
If times is less than 1, an empty string is returned.
Example:
Definition at line 8462 of file qstring.cpp.
QString & QString::replace | ( | const QChar * | before, |
qsizetype | blen, | ||
const QChar * | after, | ||
qsizetype | alen, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) |
Definition at line 3863 of file qstring.cpp.
QString & QString::replace | ( | const QString & | before, |
const QString & | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) |
Definition at line 3844 of file qstring.cpp.
QString & QString::replace | ( | const QString & | before, |
QLatin1StringView | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) |
Definition at line 4049 of file qstring.cpp.
QString & QString::replace | ( | QChar | before, |
QChar | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) |
Definition at line 3947 of file qstring.cpp.
QString & QString::replace | ( | QChar | c, |
const QString & | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) |
Definition at line 3905 of file qstring.cpp.
QString & QString::replace | ( | QChar | c, |
QLatin1StringView | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) |
Definition at line 4070 of file qstring.cpp.
QString & QString::replace | ( | QLatin1StringView | before, |
const QString & | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) |
Definition at line 4026 of file qstring.cpp.
QString & QString::replace | ( | QLatin1StringView | before, |
QLatin1StringView | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) |
Definition at line 4000 of file qstring.cpp.
Definition at line 3797 of file qstring.cpp.
Replaces n characters beginning at index position with the string after and returns a reference to this string.
Example:
Definition at line 3785 of file qstring.cpp.
Definition at line 3816 of file qstring.cpp.
Ensures the string has space for at least size characters.
If you know in advance how large a string will be, you can call this function to save repeated reallocation while building it. This can improve performance when building a string incrementally. A long sequence of operations that add to a string may trigger several reallocations, the last of which may leave you with significantly more space than you need. This is less efficient than doing a single allocation of the right size at the start.
If in doubt about how much space shall be needed, it is usually better to use an upper bound as size, or a high estimate of the most likely size, if a strict upper bound would be much bigger than this. If size is an underestimate, the string will grow as needed once the reserved size is exceeded, which may lead to a larger allocation than your best overestimate would have and will slow the operation that triggers it.
This function is useful for code that needs to build up a long string and wants to avoid repeated reallocation. In this example, we want to add to the string until some condition is true
, and we're fairly sure that size is large enough to make a call to reserve() worthwhile:
Sets the size of the string to size characters.
If size is greater than the current size, the string is extended to make it size characters long with the extra characters added to the end. The new characters are uninitialized.
If size is less than the current size, characters beyond position size are excluded from the string.
Example:
If you want to append a certain number of identical characters to the string, use the \l {QString::}{resize(qsizetype, QChar)} overload.
If you want to expand the string so that it reaches a certain width and fill the new positions with a particular character, use the leftJustified() function:
If size is negative, it is equivalent to passing zero.
Definition at line 2660 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Unlike \l {QString::}{resize(qsizetype)}, this overload initializes the new characters to fillChar:
Definition at line 2682 of file qstring.cpp.
Sets the size of the string to size characters. If the size of the string grows, the new characters are uninitialized.
The behavior is identical to {resize(size)}.
Definition at line 2703 of file qstring.cpp.
|
nodiscard |
Returns a string of size() width that contains the fill character followed by the string.
For example:
If truncate is false
and the size() of the string is more than width, then the returned string is a copy of the string.
If truncate is true and the size() of the string is more than width, then the resulting string is truncated at position width.
Definition at line 7145 of file qstring.cpp.
|
nodiscard |
Definition at line 5096 of file qstring.cpp.
|
inlinenodiscard |
This function returns a section of the string.
This string is treated as a sequence of fields separated by the character, sep. The returned string consists of the fields from position start to position end inclusive. If end is not specified, all fields from position start to the end of the string are included. Fields are numbered 0, 1, 2, etc., counting from the left, and -1, -2, etc., counting from right to left.
The flags argument can be used to affect some aspects of the function's behavior, e.g. whether to be case sensitive, whether to skip empty fields and how to deal with leading and trailing separators; see \l{SectionFlags}.
If start or end is negative, we count fields from the right of the string, the right-most field being -1, the one from right-most field being -2, and so on.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the string to the printed value of n, formatted according to the given format and precision, and returns a reference to the string.
Definition at line 8113 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the string to the printed value of n, formatted according to the given format and precision, and returns a reference to the string.
The formatting always uses QLocale::C, i.e., English/UnitedStates. To get a localized string representation of a number, use QLocale::toString() with the appropriate locale.
|
inline |
Sets the string to the printed value of n in the specified base, and returns a reference to the string.
The base is 10 by default and must be between 2 and 36.
The formatting always uses QLocale::C, i.e., English/UnitedStates. To get a localized string representation of a number, use QLocale::toString() with the appropriate locale.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 8081 of file qstring.cpp.
QString & QString::setNum | ( | qulonglong | n, |
int | base = 10 ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 8089 of file qstring.cpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Resets the QString to use the first size Unicode characters in the array unicode. The data in unicode is not copied. The caller must be able to guarantee that unicode will not be deleted or modified as long as the QString (or an unmodified copy of it) exists.
This function can be used instead of fromRawData() to re-use existings QString objects to save memory re-allocations.
Definition at line 9446 of file qstring.cpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Resizes the string to size characters and copies unicode into the string.
If unicode is \nullptr, nothing is copied, but the string is still resized to size.
Definition at line 6134 of file qstring.cpp.
Resizes the string to size characters and copies unicode into the string.
If unicode is \nullptr, nothing is copied, but the string is still resized to size.
Note that unlike fromUtf16(), this function does not consider BOMs and possibly differing byte ordering.
|
inline |
|
inline |
|
inlineconstexprnoexcept |
Modifies this string to start at position pos and extending to its end, and returns a reference to this string.
Modifies this string to start at position pos, up to, but not including, the character (code point) at index position {pos +
n}; and returns a reference to this string.
|
nodiscard |
|
nodiscard |
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
If sep does not match anywhere in the string, split() returns a single-element list containing this string.
cs specifies whether sep should be matched case sensitively or case insensitively.
If behavior is Qt::SkipEmptyParts, empty entries don't appear in the result. By default, empty entries are kept.
Example:
If sep is empty, split() returns an empty string, followed by each of the string's characters, followed by another empty string:
To understand this behavior, recall that the empty string matches everywhere, so the above is qualitatively the same as:
Definition at line 8305 of file qstring.cpp.
|
nodiscard |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 8314 of file qstring.cpp.
|
inline |
Releases any memory not required to store the character data.
The sole purpose of this function is to provide a means of fine tuning QString's memory usage. In general, you will rarely ever need to call this function.
bool QString::startsWith | ( | const QString & | s, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) const |
Returns true
if the string starts with s; otherwise returns false
.
{search-comparison-case-sensitivity} {search}
Definition at line 5468 of file qstring.cpp.
bool QString::startsWith | ( | QChar | c, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) const |
Definition at line 5487 of file qstring.cpp.
bool QString::startsWith | ( | QLatin1StringView | s, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive ) const |
Definition at line 5476 of file qstring.cpp.
|
inlinenodiscardnoexcept |
Returns true
if the string starts with the string view str; otherwise returns false
.
{search-comparison-case-sensitivity} {search}
double QString::toDouble | ( | bool * | ok = nullptr | ) | const |
Returns the string converted to a double
value.
Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).
If ok is not \nullptr, failure is reported by setting *{ok} to false
, and success by setting *{ok} to true
.
The string conversion will always happen in the 'C' locale. For locale-dependent conversion use QLocale::toDouble()
For historical reasons, this function does not handle thousands group separators. If you need to convert such numbers, use QLocale::toDouble().
This function ignores leading and trailing whitespace.
Definition at line 7991 of file qstring.cpp.
float QString::toFloat | ( | bool * | ok = nullptr | ) | const |
Returns the string converted to a float
value.
Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).
If ok is not \nullptr, failure is reported by setting *{ok} to false
, and success by setting *{ok} to true
.
The string conversion will always happen in the 'C' locale. For locale-dependent conversion use QLocale::toFloat()
For historical reasons, this function does not handle thousands group separators. If you need to convert such numbers, use QLocale::toFloat().
Example:
This function ignores leading and trailing whitespace.
Definition at line 8037 of file qstring.cpp.
|
nodiscard |
Converts a plain text string to an HTML string with HTML metacharacters {<},
{>},
{&}, and
{"} replaced by HTML entities.
Example:
Definition at line 10119 of file qstring.cpp.
|
inline |
Returns the string converted to an int
using base base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
If ok is not \nullptr, failure is reported by setting *{ok} to false
, and success by setting *{ok} to true
.
If base is 0, the C language convention is used: if the string begins with "0x", base 16 is used; otherwise, if the string begins with "0b", base 2 is used; otherwise, if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale-dependent conversion use QLocale::toInt()
Example:
This function ignores leading and trailing whitespace.
|
inlinenodiscard |
|
inlinenodiscard |
|
inlinenodiscard |
|
inlinenodiscard |
|
inline |
Returns the string converted to a long
using base base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
If ok is not \nullptr, failure is reported by setting *{ok} to false
, and success by setting *{ok} to true
.
If base is 0, the C language convention is used: if the string begins with "0x", base 16 is used; otherwise, if the string begins with "0b", base 2 is used; otherwise, if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale-dependent conversion use QLocale::toLongLong()
Example:
This function ignores leading and trailing whitespace.
qlonglong QString::toLongLong | ( | bool * | ok = nullptr, |
int | base = 10 ) const |
Returns the string converted to a {long long} using base base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
If ok is not \nullptr, failure is reported by setting *{ok} to false
, and success by setting *{ok} to true
.
If base is 0, the C language convention is used: if the string begins with "0x", base 16 is used; otherwise, if the string begins with "0b", base 2 is used; otherwise, if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale-dependent conversion use QLocale::toLongLong()
Example:
This function ignores leading and trailing whitespace.
|
inline |
Returns the string converted to a short
using base base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
If ok is not \nullptr, failure is reported by setting *{ok} to false
, and success by setting *{ok} to true
.
If base is 0, the C language convention is used: if the string begins with "0x", base 16 is used; otherwise, if the string begins with "0b", base 2 is used; otherwise, if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale-dependent conversion use QLocale::toShort()
Example:
This function ignores leading and trailing whitespace.
std::string QString::toStdString | ( | ) | const |
Returns a std::string object with the data contained in this QString.
The Unicode data is converted into 8-bit characters using the toUtf8() function.
This method is mostly useful to pass a QString to a function that accepts a std::string object.
Definition at line 9376 of file qstring.cpp.
|
inline |
Returns a std::u16string object with the data contained in this QString. The Unicode data is the same as returned by the utf16() method.
|
inline |
Returns a std::u32string object with the data contained in this QString. The Unicode data is the same as returned by the toUcs4() method.
|
inline |
Returns a std::wstring object with the data contained in this QString.
The std::wstring is encoded in UTF-16 on platforms where wchar_t is 2 bytes wide (for example, Windows) and in UTF-32 on platforms where wchar_t is 4 bytes wide (most Unix systems).
This method is mostly useful to pass a QString to a function that accepts a std::wstring object.
Returns a UCS-4/UTF-32 representation of the string as a QList<uint>.
UTF-32 is a Unicode codec and therefore it is lossless. All characters from this string will be encoded in UTF-32. Any invalid sequence of code units in this string is replaced by the Unicode replacement character (QChar::ReplacementCharacter, which corresponds to {U+FFFD}).
The returned list is not 0-terminated.
Definition at line 5856 of file qstring.cpp.
|
inline |
Returns the string converted to an {unsigned int} using base base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
If ok is not \nullptr, failure is reported by setting *{ok} to false
, and success by setting *{ok} to true
.
If base is 0, the C language convention is used: if the string begins with "0x", base 16 is used; otherwise, if the string begins with "0b", base 2 is used; otherwise, if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale-dependent conversion use QLocale::toUInt()
Example:
This function ignores leading and trailing whitespace.
|
inline |
Returns the string converted to an {unsigned long} using base base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
If ok is not \nullptr, failure is reported by setting *{ok} to false
, and success by setting *{ok} to true
.
If base is 0, the C language convention is used: if the string begins with "0x", base 16 is used; otherwise, if the string begins with "0b", base 2 is used; otherwise, if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale-dependent conversion use QLocale::toULongLong()
Example:
This function ignores leading and trailing whitespace.
qulonglong QString::toULongLong | ( | bool * | ok = nullptr, |
int | base = 10 ) const |
Returns the string converted to an {unsigned long long} using base base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
If ok is not \nullptr, failure is reported by setting *{ok} to false
, and success by setting *{ok} to true
.
If base is 0, the C language convention is used: if the string begins with "0x", base 16 is used; otherwise, if the string begins with "0b", base 2 is used; otherwise, if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale-dependent conversion use QLocale::toULongLong()
Example:
This function ignores leading and trailing whitespace.
|
inline |
Returns the string converted to an {unsigned short} using base base, which is 10 by default and must be between 2 and 36, or 0.
Returns 0 if the conversion fails.
If ok is not \nullptr, failure is reported by setting *{ok} to false
, and success by setting *{ok} to true
.
If base is 0, the C language convention is used: if the string begins with "0x", base 16 is used; otherwise, if the string begins with "0b", base 2 is used; otherwise, if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale-dependent conversion use QLocale::toUShort()
Example:
This function ignores leading and trailing whitespace.
|
inlinenodiscard |
|
inlinenodiscard |
|
inline |
Fills the array with the data contained in this QString object. The array is encoded in UTF-16 on platforms where wchar_t is 2 bytes wide (e.g. windows) and in UTF-32 on platforms where wchar_t is 4 bytes wide (most Unix systems).
array has to be allocated by the caller and contain enough space to hold the complete string (allocating the array with the same length as the string is always sufficient).
This function returns the actual length of the string in array.
Truncates the string starting from, and including, the element at index position.
If the specified position index is beyond the end of the string, nothing happens.
Example:
If position is negative, it is equivalent to passing zero.
Definition at line 6368 of file qstring.cpp.
|
inline |
Returns a Unicode representation of the string.
The result remains valid until the string is modified.
const ushort * QString::utf16 | ( | ) | const |
Returns the QString as a '\0\'-terminated array of unsigned shorts.
The result remains valid until the string is modified.
The returned string is in host byte order.
Definition at line 7054 of file qstring.cpp.
|
static |
Equivalent method to asprintf(), but takes a va_list ap instead a list of variable arguments. See the asprintf() documentation for an explanation of cformat.
This method does not call the va_end macro, the caller is responsible to call va_end on ap.
Definition at line 7444 of file qstring.cpp.
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
\macro QStringLiteral(str)
The macro generates the data for a QString out of the string literal str at compile time. Creating a QString from it is free in this case, and the generated string data is stored in the read-only segment of the compiled object file.
If you have code that looks like this:
then a temporary QString will be created to be passed as the {hasAttribute} function parameter. This can be quite expensive, as it involves a memory allocation and the copy/conversion of the data into QString's internal encoding.
This cost can be avoided by using QStringLiteral instead:
In this case, QString's internal data will be generated at compile time; no conversion or allocation will occur at runtime.
Using QStringLiteral instead of a double quoted plain C++ string literal can significantly speed up creation of QString instances from data known at compile time.
{u} in those cases. It is optional otherwise.Literal operator that creates a QString out of the first size characters in the char16_t string literal str.
The QString is created at compile time, and the generated string data is stored in the read-only segment of the compiled object file. Duplicate literals may share the same read-only memory. This functionality is interchangeable with QStringLiteral, but saves typing when many string literals are present in the code.
The following code creates a QString:
Returns a string which is the result of concatenating s1 and s2 (s1 is converted to Unicode using the QString::fromUtf8() function).
|
Returns a string which is the result of concatenating s1 and s2 (s2 is converted to Unicode using the QString::fromUtf8() function).
|
Writes the given string to the specified stream.
|
Reads a string from the specified stream into the given string.
|
friend |
|
friend |
|
friend |
QString static QString qsizetype Qt::CaseSensitivity QString::cs = Qt::CaseSensitive) const |
qsizetype Qt::CaseSensitivity QString::cs = Qt::CaseSensitive) const |