QtBase  v6.3.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
QString Class Reference

The QString class provides a Unicode character string. More...

#include <qstring.h>

Inheritance diagram for QString:
Inheritance graph
[legend]

Public Types

enum  SectionFlag {
  SectionDefault = 0x00 , SectionSkipEmpty = 0x01 , SectionIncludeLeadingSep = 0x02 , SectionIncludeTrailingSep = 0x04 ,
  SectionCaseInsensitiveSeps = 0x08
}
 
enum  NormalizationForm { NormalizationForm_D , NormalizationForm_C , NormalizationForm_KD , NormalizationForm_KC }
 
typedef QStringPrivate DataPointer
 
typedef QChariterator
 
typedef const QCharconst_iterator
 
typedef iterator Iterator
 
typedef const_iterator ConstIterator
 
typedef std::reverse_iterator< iteratorreverse_iterator
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 
typedef qsizetype size_type
 
typedef qptrdiff difference_type
 
typedef const QCharconst_reference
 
typedef QCharreference
 
typedef QCharpointer
 
typedef const QCharconst_pointer
 
typedef QChar value_type
 

Public Member Functions

constexpr QString () noexcept
 
 QString (const QChar *unicode, qsizetype size=-1)
 
 QString (QChar c)
 
 QString (qsizetype size, QChar c)
 
 QString (QLatin1String latin1)
 
 QString (const QString &) noexcept
 
 ~QString ()
 
QStringoperator= (QChar c)
 
QStringoperator= (const QString &) noexcept
 
QStringoperator= (QLatin1String latin1)
 
 QString (QString &&other) noexcept=default
 
void swap (QString &other) noexcept
 
qsizetype size () const
 
qsizetype count () const
 
qsizetype length () const
 
bool isEmpty () const
 
void resize (qsizetype size)
 
void resize (qsizetype size, QChar fillChar)
 
QStringfill (QChar c, qsizetype size=-1)
 
void truncate (qsizetype pos)
 
void chop (qsizetype n)
 
qsizetype capacity () const
 
void reserve (qsizetype size)
 
void squeeze ()
 
const QCharunicode () const
 
QChardata ()
 
const QChardata () const
 
const QCharconstData () const
 
void detach ()
 
bool isDetached () const
 
bool isSharedWith (const QString &other) const
 
void clear ()
 
const QChar at (qsizetype i) const
 
const QChar operator[] (qsizetype i) const
 
QCharoperator[] (qsizetype i)
 
QChar front () const
 
QCharfront ()
 
QChar back () const
 
QCharback ()
 
QString arg (qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (qulonglong a, int fieldwidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (long a, int fieldwidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (ulong a, int fieldwidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (int a, int fieldWidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (uint a, int fieldWidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (short a, int fieldWidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (ushort a, int fieldWidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (double a, int fieldWidth=0, char format='g', int precision=-1, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (char a, int fieldWidth=0, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (QChar a, int fieldWidth=0, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (const QString &a, int fieldWidth=0, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (QStringView a, int fieldWidth=0, QChar fillChar=QLatin1Char(' ')) const
 
QString arg (QLatin1String a, int fieldWidth=0, QChar fillChar=QLatin1Char(' ')) const
 
QString ::type arg (Args &&...args) const
 
static QString static QString qsizetype indexOf (QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
qsizetype indexOf (QLatin1String 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
 
qsizetype lastIndexOf (QChar c, qsizetype from, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
qsizetype lastIndexOf (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
qsizetype lastIndexOf (QLatin1String 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
 
bool contains (QLatin1String 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
 
qsizetype count (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
QString section (QChar sep, qsizetype start, qsizetype end=-1, SectionFlags flags=SectionDefault) const
 
QString section (const QString &in_sep, qsizetype start, qsizetype end=-1, SectionFlags flags=SectionDefault) const
 
QString left (qsizetype n) const
 
QString right (qsizetype n) const
 
QString mid (qsizetype position, qsizetype n=-1) const
 
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
 
bool startsWith (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool startsWith (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool startsWith (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool startsWith (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool endsWith (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool endsWith (QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool endsWith (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool endsWith (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
bool isUpper () const
 
bool isLower () const
 
QString leftJustified (qsizetype width, QChar fill=QLatin1Char(' '), bool trunc=false) const
 
QString rightJustified (qsizetype width, QChar fill=QLatin1Char(' '), bool trunc=false) const
 
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
 
QStringinsert (qsizetype i, QChar c)
 
QStringinsert (qsizetype i, const QChar *uc, qsizetype len)
 
QStringinsert (qsizetype i, const QString &s)
 
QStringinsert (qsizetype i, QStringView v)
 
QStringinsert (qsizetype i, QLatin1String s)
 
QStringappend (QChar c)
 
QStringappend (const QChar *uc, qsizetype len)
 
QStringappend (const QString &s)
 
QStringappend (QStringView v)
 
QStringappend (QLatin1String s)
 
QStringprepend (QChar c)
 
QStringprepend (const QChar *uc, qsizetype len)
 
QStringprepend (const QString &s)
 
QStringprepend (QStringView v)
 
QStringprepend (QLatin1String s)
 
QStringoperator+= (QChar c)
 
QStringoperator+= (const QString &s)
 
QStringoperator+= (QStringView v)
 
QStringoperator+= (QLatin1String s)
 
QStringremove (qsizetype i, qsizetype len)
 
QStringremove (QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QStringremove (QLatin1String s, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QStringremove (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
template<typename Predicate >
QStringremoveIf (Predicate pred)
 
QStringreplace (qsizetype i, qsizetype len, QChar after)
 
QStringreplace (qsizetype i, qsizetype len, const QChar *s, qsizetype slen)
 
QStringreplace (qsizetype i, qsizetype len, const QString &after)
 
QStringreplace (QChar before, QChar after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QStringreplace (const QChar *before, qsizetype blen, const QChar *after, qsizetype alen, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QStringreplace (QLatin1String before, QLatin1String after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QStringreplace (QLatin1String before, const QString &after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QStringreplace (const QString &before, QLatin1String after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QStringreplace (const QString &before, const QString &after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QStringreplace (QChar c, const QString &after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QStringreplace (QChar c, QLatin1String after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
QStringList split (const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
QStringList split (QChar sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 
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
 
QString repeated (qsizetype times) const
 
const ushortutf16 () const
 
QByteArray toLatin1 () const &
 
QByteArray toLatin1 () &&
 
QByteArray toUtf8 () const &
 
QByteArray toUtf8 () &&
 
QByteArray toLocal8Bit () const &
 
QByteArray toLocal8Bit () &&
 
QList< uinttoUcs4 () const
 
qsizetype toWCharArray (wchar_t *array) const
 
QStringsetRawData (const QChar *unicode, qsizetype size)
 
QStringsetUnicode (const QChar *unicode, qsizetype size)
 
QStringsetUtf16 (const ushort *utf16, qsizetype size)
 
int compare (const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
int compare (QLatin1String 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
 
ushort toUShort (bool *ok=nullptr, int base=10) const
 
int toInt (bool *ok=nullptr, int base=10) const
 
uint toUInt (bool *ok=nullptr, int base=10) const
 
long toLong (bool *ok=nullptr, int base=10) const
 
ulong toULong (bool *ok=nullptr, int base=10) const
 
qlonglong toLongLong (bool *ok=nullptr, int base=10) const
 
qulonglong toULongLong (bool *ok=nullptr, int base=10) const
 
float toFloat (bool *ok=nullptr) const
 
double toDouble (bool *ok=nullptr) const
 
QStringsetNum (short, int base=10)
 
QStringsetNum (ushort, int base=10)
 
QStringsetNum (int, int base=10)
 
QStringsetNum (uint, int base=10)
 
QStringsetNum (long, int base=10)
 
QStringsetNum (ulong, int base=10)
 
QStringsetNum (qlonglong, int base=10)
 
QStringsetNum (qulonglong, int base=10)
 
QStringsetNum (float, char format='g', int precision=6)
 
QStringsetNum (double, char format='g', int precision=6)
 
QT_ASCII_CAST_WARN QString (const char *ch)
 
QT_ASCII_CAST_WARN QString (const QByteArray &a)
 
QT_ASCII_CAST_WARN QStringoperator= (const char *ch)
 
QT_ASCII_CAST_WARN QStringoperator= (const QByteArray &a)
 
QT_ASCII_CAST_WARN QStringprepend (const char *s)
 
QT_ASCII_CAST_WARN QStringprepend (const QByteArray &s)
 
QT_ASCII_CAST_WARN QStringappend (const char *s)
 
QT_ASCII_CAST_WARN QStringappend (const QByteArray &s)
 
QT_ASCII_CAST_WARN QStringinsert (qsizetype i, const char *s)
 
QT_ASCII_CAST_WARN QStringinsert (qsizetype i, const QByteArray &s)
 
QT_ASCII_CAST_WARN QStringoperator+= (const char *s)
 
QT_ASCII_CAST_WARN QStringoperator+= (const QByteArray &s)
 
QT_ASCII_CAST_WARN bool operator== (const char *s) const
 
QT_ASCII_CAST_WARN bool operator!= (const char *s) const
 
QT_ASCII_CAST_WARN bool operator< (const char *s) const
 
QT_ASCII_CAST_WARN bool operator<= (const char *s) const
 
QT_ASCII_CAST_WARN bool operator> (const char *s) const
 
QT_ASCII_CAST_WARN bool operator>= (const char *s) const
 
QT_ASCII_CAST_WARN bool operator== (const QByteArray &s) const
 
QT_ASCII_CAST_WARN bool operator!= (const QByteArray &s) const
 
QT_ASCII_CAST_WARN bool operator< (const QByteArray &s) const
 
QT_ASCII_CAST_WARN bool operator> (const QByteArray &s) const
 
QT_ASCII_CAST_WARN bool operator<= (const QByteArray &s) const
 
QT_ASCII_CAST_WARN bool operator>= (const QByteArray &s) const
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
const_iterator constBegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cend () const
 
const_iterator constEnd () const
 
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)
 
void push_back (const QString &s)
 
void push_front (QChar c)
 
void push_front (const QString &s)
 
void shrink_to_fit ()
 
iterator erase (const_iterator first, const_iterator last)
 
std::string toStdString () const
 
std::wstring toStdWString () const
 
std::u16string toStdU16String () const
 
std::u32string toStdU32String () const
 
bool isNull () const
 
bool isSimpleText () const
 
bool isRightToLeft () const
 
bool isValidUtf16 () const noexcept
 
 QString (qsizetype size, Qt::Initialization)
 
 QString (DataPointer &&dd)
 
DataPointerdata_ptr ()
 
const DataPointerdata_ptr () const
 

Static Public Member Functions

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)
 
static Q_WEAK_OVERLOAD QString fromLatin1 (const QByteArray &ba)
 
static QString fromLatin1 (const char *str, qsizetype size)
 
static QString fromUtf8 (QByteArrayView utf8)
 
static Q_WEAK_OVERLOAD QString fromUtf8 (const QByteArray &ba)
 
static QString fromUtf8 (const char *utf8, qsizetype size)
 
static QString fromLocal8Bit (QByteArrayView ba)
 
static Q_WEAK_OVERLOAD QString fromLocal8Bit (const QByteArray &ba)
 
static QString fromLocal8Bit (const char *str, qsizetype size)
 
static QString fromUtf16 (const char16_t *, qsizetype size=-1)
 
static QString fromUcs4 (const char32_t *, qsizetype size=-1)
 
static QString fromRawData (const QChar *, qsizetype size)
 
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, QLatin1String s2, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
 
static int compare (QLatin1String 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)
 
static int localeAwareCompare (QStringView s1, QStringView s2)
 
static QString number (int, int base=10)
 
static QString number (uint, int base=10)
 
static QString number (long, int base=10)
 
static QString number (ulong, int base=10)
 
static QString number (qlonglong, int base=10)
 
static QString number (qulonglong, int base=10)
 
static QString number (double, char format='g', int precision=6)
 
static QString fromStdString (const std::string &s)
 
static QString fromStdWString (const std::wstring &s)
 
static QString fromStdU16String (const std::u16string &s)
 
static QString fromStdU32String (const std::u32string &s)
 

Friends

class QStringView
 
class QByteArray
 
struct QAbstractConcatenable
 
bool operator== (const QString &s1, const QString &s2) noexcept
 
bool operator< (const QString &s1, const QString &s2) noexcept
 
bool operator> (const QString &s1, const QString &s2) noexcept
 
bool operator!= (const QString &s1, const QString &s2) noexcept
 
bool operator<= (const QString &s1, const QString &s2) noexcept
 
bool operator>= (const QString &s1, const QString &s2) noexcept
 
bool operator== (const QString &s1, QLatin1String s2) noexcept
 
bool operator< (const QString &s1, QLatin1String s2) noexcept
 
bool operator> (const QString &s1, QLatin1String s2) noexcept
 
bool operator!= (const QString &s1, QLatin1String s2) noexcept
 
bool operator<= (const QString &s1, QLatin1String s2) noexcept
 
bool operator>= (const QString &s1, QLatin1String s2) noexcept
 
bool operator== (QLatin1String s1, const QString &s2) noexcept
 
bool operator< (QLatin1String s1, const QString &s2) noexcept
 
bool operator> (QLatin1String s1, const QString &s2) noexcept
 
bool operator!= (QLatin1String s1, const QString &s2) noexcept
 
bool operator<= (QLatin1String s1, const QString &s2) noexcept
 
bool operator>= (QLatin1String s1, const QString &s2) noexcept
 
bool operator== (const QString &s1, std::nullptr_t) noexcept
 
bool operator!= (const QString &s1, std::nullptr_t) noexcept
 
bool operator< (const QString &, std::nullptr_t) noexcept
 
bool operator> (const QString &s1, std::nullptr_t) noexcept
 
bool operator<= (const QString &s1, std::nullptr_t) noexcept
 
bool operator>= (const QString &, std::nullptr_t) noexcept
 
bool operator== (std::nullptr_t, const QString &s2) noexcept
 
bool operator!= (std::nullptr_t, const QString &s2) noexcept
 
bool operator< (std::nullptr_t, const QString &s2) noexcept
 
bool operator> (std::nullptr_t, const QString &s2) noexcept
 
bool operator<= (std::nullptr_t, const QString &s2) noexcept
 
bool operator>= (std::nullptr_t, const QString &s2) noexcept
 
bool operator== (const QString &s1, const char16_t *s2) noexcept
 
bool operator!= (const QString &s1, const char16_t *s2) noexcept
 
bool operator< (const QString &s1, const char16_t *s2) noexcept
 
bool operator> (const QString &s1, const char16_t *s2) noexcept
 
bool operator<= (const QString &s1, const char16_t *s2) noexcept
 
bool operator>= (const QString &s1, const char16_t *s2) noexcept
 
bool operator== (const char16_t *s1, const QString &s2) noexcept
 
bool operator!= (const char16_t *s1, const QString &s2) noexcept
 
bool operator< (const char16_t *s1, const QString &s2) noexcept
 
bool operator> (const char16_t *s1, const QString &s2) noexcept
 
bool operator<= (const char16_t *s1, const QString &s2) noexcept
 
bool operator>= (const char16_t *s1, const QString &s2) noexcept
 
bool operator== (QChar lhs, const QString &rhs) noexcept
 
bool operator< (QChar lhs, const QString &rhs) noexcept
 
bool operator> (QChar lhs, const QString &rhs) noexcept
 
bool operator!= (QChar lhs, const QString &rhs) noexcept
 
bool operator<= (QChar lhs, const QString &rhs) noexcept
 
bool operator>= (QChar lhs, const QString &rhs) noexcept
 
bool operator== (const QString &lhs, QChar rhs) noexcept
 
bool operator!= (const QString &lhs, QChar rhs) noexcept
 
bool operator< (const QString &lhs, QChar rhs) noexcept
 
bool operator> (const QString &lhs, QChar rhs) noexcept
 
bool operator<= (const QString &lhs, QChar rhs) noexcept
 
bool operator>= (const QString &lhs, QChar rhs) noexcept
 
QT_ASCII_CAST_WARN friend bool operator== (const char *s1, const QString &s2)
 
QT_ASCII_CAST_WARN friend bool operator!= (const char *s1, const QString &s2)
 
QT_ASCII_CAST_WARN friend bool operator< (const char *s1, const QString &s2)
 
QT_ASCII_CAST_WARN friend bool operator> (const char *s1, const QString &s2)
 
QT_ASCII_CAST_WARN friend bool operator<= (const char *s1, const QString &s2)
 
QT_ASCII_CAST_WARN friend bool operator>= (const char *s1, const QString &s2)
 

Related Functions

(Note that these are not member functions.)

const QString operator+ (const QString &s1, const QString &s2)
 
const QString operator+ (const QString &s1, const char *s2)
 
const QString operator+ (const char *s1, const QString &s2)
 
 localeAwareCompare
 
QDataStreamoperator<< (QDataStream &stream, const QString &string)
 
QDataStreamoperator>> (QDataStream &stream, QString &string)
 
 operator""_qs (const char16_t *str, size_t size)
 
template< typename T > qsizetype erase (QString &s, const T &t)
 
template< typename Predicate > qsizetype erase_if (QString &s, Predicate pred)
 

Detailed Description

The QString class provides a Unicode character string.

\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, QLatin1String or similar.

Using this macro together with source strings outside the 7-bit range, non-literals, or literals with embedded NUL characters is undefined.

See also
QT_NO_CAST_FROM_ASCII, QT_NO_CAST_TO_ASCII

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

See also
QT_NO_CAST_TO_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY

\macro QT_NO_CAST_TO_ASCII

Disables automatic conversion from QString to 8-bit strings ({char *}).

See also
QT_NO_CAST_FROM_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY

\macro QT_ASCII_CAST_WARNINGS

\inmodule QtCore \reentrant

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, i.e., 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 will be easy to translate if you want to expand your application's market at some point. The two main cases where QByteArray is appropriate are when you need to store raw binary data, and when memory conservation is critical (like in embedded systems).

Definition at line 387 of file qstring.h.

Member Typedef Documentation

◆ const_iterator

See also
QString::iterator

Definition at line 1026 of file qstring.h.

◆ const_pointer

The QString::const_pointer typedef provides an STL-style const pointer to a QString element (QChar).

Definition at line 1052 of file qstring.h.

◆ const_reference

Definition at line 1049 of file qstring.h.

◆ const_reverse_iterator

Since
5.6
See also
QString::reverse_iterator, QString::const_iterator

Definition at line 1030 of file qstring.h.

◆ ConstIterator

Qt-style synonym for QString::const_iterator.

Definition at line 1028 of file qstring.h.

◆ DataPointer

Definition at line 391 of file qstring.h.

◆ difference_type

Definition at line 1048 of file qstring.h.

◆ iterator

See also
QString::const_iterator

Definition at line 1025 of file qstring.h.

◆ Iterator

Qt-style synonym for QString::iterator.

Definition at line 1027 of file qstring.h.

◆ pointer

The QString::pointer typedef provides an STL-style pointer to a QString element (QChar).

Definition at line 1051 of file qstring.h.

◆ reference

Definition at line 1050 of file qstring.h.

◆ reverse_iterator

Since
5.6
See also
QString::const_reverse_iterator, QString::iterator

Definition at line 1029 of file qstring.h.

◆ size_type

Definition at line 1047 of file qstring.h.

◆ value_type

Definition at line 1053 of file qstring.h.

Member Enumeration Documentation

◆ NormalizationForm

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

See also
normalized(), {https://www.unicode.org/reports/tr15/}{Unicode Standard Annex #15}
Enumerator
NormalizationForm_D 
NormalizationForm_C 
NormalizationForm_KD 
NormalizationForm_KC 

Definition at line 732 of file qstring.h.

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

See also
section()
Enumerator
SectionDefault 
SectionSkipEmpty 
SectionIncludeLeadingSep 
SectionIncludeTrailingSep 
SectionCaseInsensitiveSeps 

Definition at line 558 of file qstring.h.

Constructor & Destructor Documentation

◆ QString() [1/11]

constexpr QString::QString ( )
inlineconstexprnoexcept

Constructs a null string. Null strings are also empty.

See also
isEmpty()

Definition at line 1304 of file qstring.h.

Here is the caller graph for this function:

◆ QString() [2/11]

QString::QString ( const QChar unicode,
qsizetype  size = -1 
)
explicit

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.

See also
fromRawData()

Definition at line 2503 of file qstring.cpp.

Here is the call graph for this function:

◆ QString() [3/11]

QString::QString ( QChar  ch)

Constructs a string of size 1 containing the character ch.

Definition at line 2573 of file qstring.cpp.

Here is the call graph for this function:

◆ QString() [4/11]

QString::QString ( qsizetype  size,
QChar  ch 
)

Constructs a string of the given size with every character set to ch.

See also
fill()

Definition at line 2530 of file qstring.cpp.

Here is the call graph for this function:

◆ QString() [5/11]

QString::QString ( QLatin1String  str)
inline

Constructs a copy of the Latin-1 string str.

See also
fromLatin1()

Definition at line 1210 of file qstring.h.

Here is the call graph for this function:

◆ QString() [6/11]

QString::QString ( const QString other)
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}.

See also
operator=()

Definition at line 1242 of file qstring.h.

◆ ~QString()

QString::~QString ( )
inline

Destroys the string.

Definition at line 1305 of file qstring.h.

◆ QString() [7/11]

QString::QString ( QString &&  other)
inlinedefaultnoexcept

Move-constructs a QString instance, making it point at the same object that other was pointing to.

Since
5.2

◆ QString() [8/11]

QString::QString ( const char *  str)
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.

Note
Defining \l QT_RESTRICTED_CAST_FROM_ASCII also disables this constructor, but enables a {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.
See also
fromLatin1(), fromLocal8Bit(), fromUtf8()

Definition at line 968 of file qstring.h.

◆ QString() [9/11]

QString::QString ( const QByteArray ba)
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.

Note
: any null ('\0') bytes in the byte array will be included in this string, converted to Unicode null characters (U+0000). This behavior is different from Qt 5.x.
See also
fromLatin1(), fromLocal8Bit(), fromUtf8()

Definition at line 971 of file qstring.h.

◆ QString() [10/11]

QString::QString ( qsizetype  size,
Qt::Initialization   
)

Definition at line 2552 of file qstring.cpp.

Here is the call graph for this function:

◆ QString() [11/11]

QString::QString ( DataPointer &&  dd)
inlineexplicit

Definition at line 1087 of file qstring.h.

Member Function Documentation

◆ append() [1/7]

QT_ASCII_CAST_WARN QString& QString::append ( const char *  s)
inline

Definition at line 984 of file qstring.h.

Here is the call graph for this function:

◆ append() [2/7]

QT_ASCII_CAST_WARN QString& QString::append ( const QByteArray s)
inline

Definition at line 986 of file qstring.h.

Here is the call graph for this function:

◆ append() [3/7]

QString & QString::append ( const QChar uc,
qsizetype  len 
)

Definition at line 3086 of file qstring.cpp.

Here is the call graph for this function:

◆ append() [4/7]

QString & QString::append ( const QString str)

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.

See also
operator+=(), prepend(), insert()

Definition at line 3068 of file qstring.cpp.

Here is the call graph for this function:

◆ append() [5/7]

QString & QString::append ( QChar  c)

Definition at line 3152 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ append() [6/7]

QString & QString::append ( QLatin1String  s)

Definition at line 3103 of file qstring.cpp.

Here is the call graph for this function:

◆ append() [7/7]

QString& QString::append ( QStringView  v)
inline

Definition at line 653 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ arg() [1/15]

template< typename...Args > QString QString::arg ( Args &&...  args) const
inline
Since
5.14

Replaces occurrences of {N} in this string with the corresponding argument from args. The arguments are not positional: the first of the args replaces the {N} with the lowest {N} (all of them), the second of the args the {N} with the next-lowest {N} etc.

Args can consist of anything that implicitly converts to QString, QStringView or QLatin1String.

In addition, the following types are also supported: QChar, QLatin1Char.

See also
QString::arg()

Definition at line 501 of file qstring.h.

Here is the call graph for this function:

◆ arg() [2/15]

QString QString::arg ( char  a,
int  fieldWidth = 0,
QChar  fillChar = QLatin1Char(' ') 
) const

Definition at line 8446 of file qstring.cpp.

Here is the call graph for this function:

◆ arg() [3/15]

QString QString::arg ( const QString a,
int  fieldWidth = 0,
QChar  fillChar = QLatin1Char(' ') 
) const

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 argument 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, the arg() replaces all of them.

If there is no unreplaced place marker remaining, a warning message is output and the result is undefined. Place marker numbers must be in the range 1 to 99.

Definition at line 8150 of file qstring.cpp.

Here is the call graph for this function:

◆ arg() [4/15]

QString QString::arg ( double  a,
int  fieldWidth = 0,
char  format = 'g',
int  precision = -1,
QChar  fillChar = QLatin1Char(' ') 
) const

Definition at line 8466 of file qstring.cpp.

◆ arg() [5/15]

QString QString::arg ( int  a,
int  fieldWidth = 0,
int  base = 10,
QChar  fillChar = QLatin1Char(' ') 
) const
inline

Definition at line 1259 of file qstring.h.

Here is the call graph for this function:

◆ arg() [6/15]

QString QString::arg ( long  a,
int  fieldwidth = 0,
int  base = 10,
QChar  fillChar = QLatin1Char(' ') 
) const
inline

Definition at line 1263 of file qstring.h.

Here is the call graph for this function:

◆ arg() [7/15]

QString QString::arg ( QChar  a,
int  fieldWidth = 0,
QChar  fillChar = QLatin1Char(' ') 
) const

Definition at line 8436 of file qstring.cpp.

Here is the call graph for this function:

◆ arg() [8/15]

QString QString::arg ( QLatin1String  a,
int  fieldWidth = 0,
QChar  fillChar = QLatin1Char(' ') 
) const

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

Since
5.10

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.

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.

Definition at line 8224 of file qstring.cpp.

Here is the call graph for this function:

◆ arg() [9/15]

QString QString::arg ( qlonglong  a,
int  fieldwidth = 0,
int  base = 10,
QChar  fillChar = QLatin1Char(' ') 
) const

Definition at line 8318 of file qstring.cpp.

Here is the caller graph for this function:

◆ arg() [10/15]

QString QString::arg ( QStringView  a,
int  fieldWidth = 0,
QChar  fillChar = QLatin1Char(' ') 
) const

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

Since
5.10

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.

Definition at line 8188 of file qstring.cpp.

◆ arg() [11/15]

QString QString::arg ( qulonglong  a,
int  fieldwidth = 0,
int  base = 10,
QChar  fillChar = QLatin1Char(' ') 
) const

Definition at line 8366 of file qstring.cpp.

◆ arg() [12/15]

QString QString::arg ( short  a,
int  fieldWidth = 0,
int  base = 10,
QChar  fillChar = QLatin1Char(' ') 
) const
inline

fieldWidth specifies the minimum amount of space that a is padded to and filled with the character fillChar. A positive value produces right-aligned text; a negative value produces left-aligned text.

The base argument specifies the base to use when converting the integer a into a string. The base must be between 2 and 36, with 8 giving octal, 10 decimal, and 16 hexadecimal numbers.

See also
{Number Formats}

Definition at line 1267 of file qstring.h.

Here is the call graph for this function:

◆ arg() [13/15]

QString QString::arg ( uint  a,
int  fieldWidth = 0,
int  base = 10,
QChar  fillChar = QLatin1Char(' ') 
) const
inline

Definition at line 1261 of file qstring.h.

Here is the call graph for this function:

◆ arg() [14/15]

QString QString::arg ( ulong  a,
int  fieldwidth = 0,
int  base = 10,
QChar  fillChar = QLatin1Char(' ') 
) const
inline

Definition at line 1265 of file qstring.h.

Here is the call graph for this function:

◆ arg() [15/15]

QString QString::arg ( ushort  a,
int  fieldWidth = 0,
int  base = 10,
QChar  fillChar = QLatin1Char(' ') 
) const
inline

Definition at line 1269 of file qstring.h.

Here is the call graph for this function:

◆ asprintf()

QString QString::asprintf ( const char *  cformat,
  ... 
)
static
Since
5.5

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.

Note
The {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.
Warning
We do not recommend using QString::asprintf() in new Qt code. Instead, consider using QTextStream or arg(), both of which support Unicode strings seamlessly and are type-safe. Here is an example that uses QTextStream:

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.

See also
arg()

Definition at line 6759 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ at()

const QChar QString::at ( qsizetype  position) const
inline

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

See also
operator[]()

Definition at line 1212 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ back() [1/2]

QChar & QString::back ( )
inline
Since
5.10

Returns a reference to the last character in the string. Same as {operator[](size() - 1)}.

This function is provided for STL compatibility.

Warning
Calling this function on an empty string constitutes undefined behavior.
See also
front(), at(), operator[]()

Definition at line 1330 of file qstring.h.

Here is the call graph for this function:

◆ back() [2/2]

QChar QString::back ( ) const
inline
Since
5.10

Returns the last character in the string. Same as {at(size() - 1)}.

This function is provided for STL compatibility.

Warning
Calling this function on an empty string constitutes undefined behavior.
See also
front(), at(), operator[]()

Definition at line 444 of file qstring.h.

Here is the call graph for this function:

◆ begin() [1/2]

QString::iterator QString::begin ( )
inline

Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first character in the string.

! [iterator-invalidation-func-desc]

Warning
The returned iterator is invalidated on detachment or when the QString is modified. ! [iterator-invalidation-func-desc]
\sa constBegin(), end()

Definition at line 1331 of file qstring.h.

Here is the caller graph for this function:

◆ begin() [2/2]

QString::const_iterator QString::begin ( ) const
inline

Definition at line 1333 of file qstring.h.

◆ capacity()

qsizetype QString::capacity ( ) const
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().

Note
a statically allocated string will report a capacity of 0, even if it's not empty.
The free space position in the allocated memory block is undefined. In other words, one should not assume that the free memory is always located after the initialized elements.
See also
reserve(), squeeze()

Definition at line 1244 of file qstring.h.

Here is the caller graph for this function:

◆ cbegin()

QString::const_iterator QString::cbegin ( ) const
inline
Since
5.0

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the string.

iterator-invalidation-func-desc

See also
begin(), cend()

Definition at line 1335 of file qstring.h.

Here is the caller graph for this function:

◆ cend()

QString::const_iterator QString::cend ( ) const
inline
Since
5.0

Returns a const \l{STL-style iterators}{STL-style iterator} pointing just after the last character in the string.

iterator-invalidation-func-desc

See also
cbegin(), end()

Definition at line 1343 of file qstring.h.

Here is the caller graph for this function:

◆ chop()

void QString::chop ( qsizetype  n)

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.

See also
truncate(), resize(), remove(), QStringView::chop()

Definition at line 5955 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ chopped()

QString QString::chopped ( qsizetype  len) const
inline
Since
5.10

Returns a string that contains the size() - len leftmost characters of this string.

Note
The behavior is undefined if len is negative or greater than size().
See also
endsWith(), first(), last(), sliced(), chop(), truncate()

Definition at line 584 of file qstring.h.

Here is the call graph for this function:

◆ clear()

void QString::clear ( )
inline

Clears the contents of the string and makes it null.

See also
resize(), isNull()

Definition at line 1240 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare() [1/9]

int QString::compare ( const QString s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
noexcept

Definition at line 6263 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare() [2/9]

int QString::compare ( const QString s1,
const QString s2,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
inlinestaticnoexcept
Since
4.2

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.

If cs is Qt::CaseSensitive, the comparison is case sensitive; otherwise the comparison is case insensitive.

Case sensitive comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with localeAwareCompare().

See also
operator==(), operator<(), operator>(), {Comparing Strings}

Definition at line 822 of file qstring.h.

◆ compare() [3/9]

static int QString::compare ( const QString s1,
QLatin1String  s2,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
inlinestaticnoexcept

Definition at line 826 of file qstring.h.

◆ compare() [4/9]

static int QString::compare ( const QString s1,
QStringView  s2,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
inlinestaticnoexcept

Definition at line 832 of file qstring.h.

◆ compare() [5/9]

int QString::compare ( QChar  ch,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inlinenoexcept

Definition at line 819 of file qstring.h.

Here is the call graph for this function:

◆ compare() [6/9]

int QString::compare ( QLatin1String  other,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
noexcept

Definition at line 6289 of file qstring.cpp.

Here is the call graph for this function:

◆ compare() [7/9]

static int QString::compare ( QLatin1String  s1,
const QString s2,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
inlinestaticnoexcept

Definition at line 829 of file qstring.h.

◆ compare() [8/9]

int QString::compare ( QStringView  s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inlinenoexcept

Definition at line 1492 of file qstring.h.

◆ compare() [9/9]

static int QString::compare ( QStringView  s1,
const QString s2,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
inlinestaticnoexcept

Definition at line 834 of file qstring.h.

◆ constBegin()

QString::const_iterator QString::constBegin ( ) const
inline

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the string.

iterator-invalidation-func-desc

See also
begin(), constEnd()

Definition at line 1337 of file qstring.h.

Here is the caller graph for this function:

◆ constData()

const QChar * QString::constData ( ) const
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.

Note
The returned string may not be '\0'-terminated. Use size() to determine the length of the array.
See also
data(), operator[](), fromRawData()

Definition at line 1234 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ constEnd()

QString::const_iterator QString::constEnd ( ) const
inline

Returns a const \l{STL-style iterators}{STL-style iterator} pointing just after the last character in the string.

iterator-invalidation-func-desc

See also
constBegin(), end()

Definition at line 1345 of file qstring.h.

Here is the caller graph for this function:

◆ contains() [1/4]

bool QString::contains ( const QString str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Returns true if this string contains an occurrence of the string str; otherwise returns false.

If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

Example:

See also
indexOf(), count()

Definition at line 1348 of file qstring.h.

Here is the call graph for this function:

◆ contains() [2/4]

bool QString::contains ( QChar  c,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Definition at line 1353 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contains() [3/4]

bool QString::contains ( QLatin1String  s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Definition at line 1351 of file qstring.h.

Here is the call graph for this function:

◆ contains() [4/4]

bool QString::contains ( QStringView  s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inlinenoexcept

Definition at line 1355 of file qstring.h.

Here is the call graph for this function:

◆ count() [1/4]

qsizetype QString::count ( ) const
inline

Definition at line 414 of file qstring.h.

Here is the caller graph for this function:

◆ count() [2/4]

qsizetype QString::count ( const QString str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns the number of (potentially overlapping) occurrences of the string str in this string.

If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

See also
contains(), indexOf()

Definition at line 4504 of file qstring.cpp.

Here is the call graph for this function:

◆ count() [3/4]

qsizetype QString::count ( QChar  c,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Definition at line 4520 of file qstring.cpp.

Here is the call graph for this function:

◆ count() [4/4]

qsizetype QString::count ( QStringView  s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Definition at line 4536 of file qstring.cpp.

Here is the call graph for this function:

◆ crbegin()

QString::const_reverse_iterator QString::crbegin ( ) const
inline
Since
5.6

Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first character in the string, in reverse order.

iterator-invalidation-func-desc

See also
begin(), rbegin(), rend()

Definition at line 1043 of file qstring.h.

Here is the call graph for this function:

◆ crend()

QString::const_reverse_iterator QString::crend ( ) const
inline
Since
5.6

Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing just after the last character in the string, in reverse order.

iterator-invalidation-func-desc

See also
end(), rend(), rbegin()

Definition at line 1044 of file qstring.h.

Here is the call graph for this function:

◆ data() [1/2]

QChar * QString::data ( )
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.

See also
constData(), operator[]()

Definition at line 1228 of file qstring.h.

Here is the caller graph for this function:

◆ data() [2/2]

const QChar * QString::data ( ) const
inline

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

Note
The returned string may not be '\0'-terminated. Use size() to determine the length of the array.
See also
fromRawData()

Definition at line 1220 of file qstring.h.

Here is the caller graph for this function:

◆ data_ptr() [1/2]

DataPtr & QString::data_ptr ( )
inline

Definition at line 1151 of file qstring.h.

Here is the caller graph for this function:

◆ data_ptr() [2/2]

const DataPointer& QString::data_ptr ( ) const
inline

Definition at line 1152 of file qstring.h.

◆ detach()

void QString::detach ( )
inline

Definition at line 1236 of file qstring.h.

Here is the caller graph for this function:

◆ end() [1/2]

QString::iterator QString::end ( )
inline

Returns an \l{STL-style iterators}{STL-style iterator} pointing just after the last character in the string.

iterator-invalidation-func-desc

See also
begin(), constEnd()

Definition at line 1339 of file qstring.h.

Here is the caller graph for this function:

◆ end() [2/2]

QString::const_iterator QString::end ( ) const
inline

Definition at line 1341 of file qstring.h.

◆ endsWith() [1/4]

bool QString::endsWith ( const QString s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns true if the string ends with s; otherwise returns false.

If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

See also
startsWith()

Definition at line 5143 of file qstring.cpp.

Here is the caller graph for this function:

◆ endsWith() [2/4]

bool QString::endsWith ( QChar  c,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Definition at line 5176 of file qstring.cpp.

◆ endsWith() [3/4]

bool QString::endsWith ( QLatin1String  s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Definition at line 5165 of file qstring.cpp.

◆ endsWith() [4/4]

bool QString::endsWith ( QStringView  s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inlinenoexcept

Definition at line 599 of file qstring.h.

Here is the call graph for this function:

◆ erase()

Since
6.1

Removes from the string the characters in the half-open range [ first , last ). Returns an iterator to the character referred to by last before the erase.

Definition at line 8883 of file qstring.cpp.

Here is the call graph for this function:

◆ fill()

QString & QString::fill ( QChar  ch,
qsizetype  size = -1 
)

Sets every character in the string to character ch. If size is different from -1 (default), the string is resized to size beforehand.

Example:

See also
resize()

Definition at line 5973 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ first()

QString QString::first ( qsizetype  n) const
inline
Since
6.0

Returns a string that contains the first n characters of this string.

Note
The behavior is undefined when n < 0 or n > size().
See also
last(), sliced(), startsWith(), chopped(), chop(), truncate()

Definition at line 576 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromLatin1() [1/3]

QString QString::fromLatin1 ( const char *  str,
qsizetype  size 
)
inlinestatic

Returns a QString initialized with the first size characters of the Latin-1 string str.

If size is {-1}, {strlen(str)} is used instead.

See also
toLatin1(), fromUtf8(), fromLocal8Bit()

Definition at line 768 of file qstring.h.

◆ fromLatin1() [2/3]

QString QString::fromLatin1 ( const QByteArray str)
inlinestatic

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

Since
5.0

Returns a QString initialized with the Latin-1 string str.

Note
: any null ('\0') bytes in the byte array will be included in this string, converted to Unicode null characters (U+0000). This behavior is different from Qt 5.x.

Definition at line 767 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromLatin1() [3/3]

QString QString::fromLatin1 ( QByteArrayView  str)
static

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

Since
6.0

Returns a QString initialized with the Latin-1 string str.

Note
: any null ('\0') bytes in the byte array will be included in this string, converted to Unicode null characters (U+0000).

Definition at line 5488 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromLocal8Bit() [1/3]

QString QString::fromLocal8Bit ( const char *  str,
qsizetype  size 
)
inlinestatic

Returns a QString initialized with the first size characters of the 8-bit string str.

If size is {-1}, {strlen(str)} is used instead.

On Unix systems this is equivalen to fromUtf8(), on Windows the systems current code page is being used.

See also
toLocal8Bit(), fromLatin1(), fromUtf8()

Definition at line 790 of file qstring.h.

◆ fromLocal8Bit() [2/3]

QString QString::fromLocal8Bit ( const QByteArray str)
inlinestatic

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

Since
5.0

Returns a QString initialized with the 8-bit string str.

Note
: any null ('\0') bytes in the byte array will be included in this string, converted to Unicode null characters (U+0000). This behavior is different from Qt 5.x.

Definition at line 789 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromLocal8Bit() [3/3]

QString QString::fromLocal8Bit ( QByteArrayView  str)
static

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

Since
6.0

Returns a QString initialized with the 8-bit string str.

Note
: any null ('\0') bytes in the byte array will be included in this string, converted to Unicode null characters (U+0000).

Definition at line 5563 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromRawData()

QString QString::fromRawData ( const QChar unicode,
qsizetype  size 
)
static

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:

Warning
A string created with fromRawData() is not '\0'-terminated, unless the raw data contains a '\0' character at position size. This means unicode() will not return a '\0'-terminated string (although utf16() does, at the cost of copying the raw data).
See also
fromUtf16(), setRawData()

Definition at line 8938 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromStdString()

QString QString::fromStdString ( const std::string str)
inlinestatic

Returns a copy of the str string. The given string is converted to Unicode using the fromUtf8() function.

See also
fromLatin1(), fromLocal8Bit(), fromUtf8(), QByteArray::fromStdString()

Definition at line 1452 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromStdU16String()

QString QString::fromStdU16String ( const std::u16string &  str)
inlinestatic
Since
5.5

Returns a copy of the str string. The given string is assumed to be encoded in UTF-16.

See also
fromUtf16(), fromStdWString(), fromStdU32String()

Definition at line 1466 of file qstring.h.

◆ fromStdU32String()

QString QString::fromStdU32String ( const std::u32string &  str)
inlinestatic
Since
5.5

Returns a copy of the str string. The given string is assumed to be encoded in UCS-4.

See also
fromUcs4(), fromStdWString(), fromStdU16String()

Definition at line 1472 of file qstring.h.

◆ fromStdWString()

QString QString::fromStdWString ( const std::wstring &  str)
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).

See also
fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdU16String(), fromStdU32String()

Definition at line 1463 of file qstring.h.

◆ fromUcs4()

QString QString::fromUcs4 ( const char32_t *  unicode,
qsizetype  size = -1 
)
static
Since
4.2
Deprecated:
[6.0] Use the char32_t overload instead.
Since
5.3

Returns a QString initialized with the first size characters of the Unicode string unicode (ISO-10646-UCS-4 encoded).

If size is -1 (default), unicode must be \0'-terminated.

See also
toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray(), fromStdU32String()

Definition at line 5690 of file qstring.cpp.

Here is the call graph for this function:

◆ fromUtf16()

QString QString::fromUtf16 ( const char16_t *  unicode,
qsizetype  size = -1 
)
static
Since
5.3 Returns a QString initialized with the first size characters of the Unicode string unicode (ISO-10646-UTF-16 encoded).

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 *, int) or QString(const QChar *) if possible.

QString makes a deep copy of the Unicode data.

See also
utf16(), setUtf16(), fromStdU16String()
Deprecated:
[6.0] Use the char16_t overload instead.

Definition at line 5658 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromUtf8() [1/3]

QString QString::fromUtf8 ( const char *  str,
qsizetype  size 
)
inlinestatic

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.

See also
toUtf8(), fromLatin1(), fromLocal8Bit()

Definition at line 775 of file qstring.h.

◆ fromUtf8() [2/3]

QString QString::fromUtf8 ( const QByteArray str)
inlinestatic

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

Since
5.0

Returns a QString initialized with the UTF-8 string str.

Note
: any null ('\0') bytes in the byte array will be included in this string, converted to Unicode null characters (U+0000). This behavior is different from Qt 5.x.

Definition at line 774 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromUtf8() [3/3]

QString QString::fromUtf8 ( QByteArrayView  str)
static

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

Since
6.0

Returns a QString initialized with the UTF-8 string str.

Note
: any null ('\0') bytes in the byte array will be included in this string, converted to Unicode null characters (U+0000).

Definition at line 5632 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromWCharArray()

QString QString::fromWCharArray ( const wchar_t *  string,
qsizetype  size = -1 
)
inlinestatic
Since
4.2

Returns a copy of the string, where the encoding of string depends on the size of wchar. If wchar is 4 bytes, the string is interpreted as UCS-4, if wchar is 2 bytes it is interpreted as UTF-16.

If size is -1 (default), the string must be '\0'-terminated.

See also
fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdWString()
Here is the caller graph for this function:

◆ front() [1/2]

QChar & QString::front ( )
inline
Since
5.10

Returns a reference to the first character in the string. Same as {operator[](0)}.

This function is provided for STL compatibility.

Warning
Calling this function on an empty string constitutes undefined behavior.
See also
back(), at(), operator[]()

Definition at line 1329 of file qstring.h.

Here is the call graph for this function:

◆ front() [2/2]

QChar QString::front ( ) const
inline
Since
5.10

Returns the first character in the string. Same as {at(0)}.

This function is provided for STL compatibility.

Warning
Calling this function on an empty string constitutes undefined behavior.
See also
back(), at(), operator[]()

Definition at line 442 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ indexOf() [1/4]

qsizetype QString::indexOf ( const QString str,
qsizetype  from = 0,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns the index position of the first occurrence of the string str in this string, searching forward from index position from. Returns -1 if str is not found.

If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

Example:

If from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.

See also
lastIndexOf(), contains(), count()

Definition at line 4142 of file qstring.cpp.

Here is the call graph for this function:

◆ indexOf() [2/4]

qsizetype QString::indexOf ( QChar  c,
qsizetype  from = 0,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Definition at line 4197 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ indexOf() [3/4]

qsizetype QString::indexOf ( QLatin1String  str,
qsizetype  from = 0,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
Since
4.5 Returns the index position of the first occurrence of the string str in this string, searching forward from index position from. Returns -1 if str is not found.

If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

Example:

If from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.

See also
lastIndexOf(), contains(), count()

Definition at line 4185 of file qstring.cpp.

Here is the call graph for this function:

◆ indexOf() [4/4]

qsizetype QString::indexOf ( QStringView  s,
qsizetype  from = 0,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inlinenoexcept

Definition at line 512 of file qstring.h.

Here is the call graph for this function:

◆ insert() [1/7]

QT_ASCII_CAST_WARN QString& QString::insert ( qsizetype  i,
const char *  s 
)
inline

Definition at line 988 of file qstring.h.

Here is the call graph for this function:

◆ insert() [2/7]

QT_ASCII_CAST_WARN QString& QString::insert ( qsizetype  i,
const QByteArray s 
)
inline

Definition at line 990 of file qstring.h.

Here is the call graph for this function:

◆ insert() [3/7]

QString & QString::insert ( qsizetype  i,
const QChar uc,
qsizetype  len 
)

Definition at line 3002 of file qstring.cpp.

Here is the call graph for this function:

◆ insert() [4/7]

QString& QString::insert ( qsizetype  i,
const QString s 
)
inline

Definition at line 643 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert() [5/7]

QString & QString::insert ( qsizetype  i,
QChar  c 
)

Definition at line 3043 of file qstring.cpp.

Here is the caller graph for this function:

◆ insert() [6/7]

QString & QString::insert ( qsizetype  i,
QLatin1String  s 
)

Definition at line 2969 of file qstring.cpp.

Here is the call graph for this function:

◆ insert() [7/7]

QString& QString::insert ( qsizetype  i,
QStringView  v 
)
inline

Definition at line 645 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isDetached()

bool QString::isDetached ( ) const
inline

Definition at line 1238 of file qstring.h.

Here is the caller graph for this function:

◆ isEmpty()

bool QString::isEmpty ( ) const
inline

Returns true if the string has no characters; otherwise returns false.

Example:

See also
size()

Definition at line 1216 of file qstring.h.

◆ isLower()

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.

Since
5.12
See also
QChar::toLower(), isUpper()

Definition at line 5220 of file qstring.cpp.

◆ isNull()

bool QString::isNull ( ) const
inline

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.

See also
isEmpty()

Definition at line 1078 of file qstring.h.

Here is the caller graph for this function:

◆ isRightToLeft()

bool QString::isRightToLeft ( ) const

Returns true if the string is read right to left.

See also
QStringView::isRightToLeft()

Definition at line 8780 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isSharedWith()

bool QString::isSharedWith ( const QString other) const
inline

Definition at line 435 of file qstring.h.

Here is the call graph for this function:

◆ isSimpleText()

bool QString::isSimpleText ( ) const

Definition at line 8758 of file qstring.cpp.

◆ isUpper()

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.

Since
5.12
See also
QChar::toUpper(), isLower()

Definition at line 5194 of file qstring.cpp.

◆ isValidUtf16()

bool QString::isValidUtf16 ( ) const
inlinenoexcept
Since
5.15

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.

See also
QStringView::isValidUtf16()

Definition at line 1083 of file qstring.h.

Here is the call graph for this function:

◆ last()

QString QString::last ( qsizetype  n) const
inline
Since
6.0

Returns the string that contains the last n characters of this string.

Note
The behavior is undefined when n < 0 or n > size().
See also
first(), sliced(), endsWith(), chopped(), chop(), truncate()

Definition at line 578 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lastIndexOf() [1/8]

qsizetype QString::lastIndexOf ( const QString str,
qsizetype  from,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns the index position of the last occurrence of the string str in this string, searching backward from index position from. If from is -1, the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if str is not found.

If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

Example:

Note
When searching for a 0-length str, the match at the end of the data is excluded from the search by a negative from, even though {-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.
See also
indexOf(), contains(), count()

Definition at line 4226 of file qstring.cpp.

Here is the call graph for this function:

◆ lastIndexOf() [2/8]

qsizetype QString::lastIndexOf ( const QString s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Definition at line 521 of file qstring.h.

Here is the call graph for this function:

◆ lastIndexOf() [3/8]

qsizetype QString::lastIndexOf ( QChar  c,
qsizetype  from,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Definition at line 4306 of file qstring.cpp.

◆ lastIndexOf() [4/8]

qsizetype QString::lastIndexOf ( QChar  c,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inlinenoexcept

Definition at line 514 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lastIndexOf() [5/8]

qsizetype QString::lastIndexOf ( QLatin1String  s,
qsizetype  from,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Definition at line 4277 of file qstring.cpp.

Here is the call graph for this function:

◆ lastIndexOf() [6/8]

qsizetype QString::lastIndexOf ( QLatin1String  s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

Definition at line 517 of file qstring.h.

Here is the call graph for this function:

◆ lastIndexOf() [7/8]

qsizetype QString::lastIndexOf ( QStringView  s,
qsizetype  from,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inlinenoexcept

Definition at line 528 of file qstring.h.

Here is the call graph for this function:

◆ lastIndexOf() [8/8]

qsizetype QString::lastIndexOf ( QStringView  s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inlinenoexcept

Definition at line 526 of file qstring.h.

Here is the call graph for this function:

◆ left()

QString QString::left ( qsizetype  n) const

Returns a substring that contains the n leftmost characters of the string.

If you know that n cannot be out of bounds, use first() instead in new code, because it is faster.

The entire string is returned if n is greater than or equal to size(), or less than zero.

See also
first(), last(), startsWith(), chopped(), chop(), truncate()

Definition at line 4951 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ leftJustified()

QString QString::leftJustified ( qsizetype  width,
QChar  fill = QLatin1Char(' '),
bool  truncate = false 
) const

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.

See also
rightJustified()

Definition at line 6518 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ length()

qsizetype QString::length ( ) const
inline

Returns the number of characters in this string. Equivalent to size().

See also
resize()

Definition at line 415 of file qstring.h.

Here is the caller graph for this function:

◆ localeAwareCompare() [1/4]

int QString::localeAwareCompare ( const QString s) const

Definition at line 6403 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ localeAwareCompare() [2/4]

int QString::localeAwareCompare ( const QString s1,
const QString s2 
)
inlinestatic

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.

See also
compare(), QLocale, {Comparing Strings}

Definition at line 839 of file qstring.h.

◆ localeAwareCompare() [3/4]

int QString::localeAwareCompare ( QStringView  s) const
inline

Definition at line 1495 of file qstring.h.

◆ localeAwareCompare() [4/4]

int QString::localeAwareCompare ( QStringView  s1,
QStringView  s2 
)
inlinestatic

Definition at line 1497 of file qstring.h.

◆ mid()

QString QString::mid ( qsizetype  position,
qsizetype  n = -1 
) const

Returns a string that contains n characters of this string, starting at the specified position index.

If you know that position and n cannot be out of bounds, use sliced() instead in new code, because it is faster.

Returns a null string if the position index exceeds the length of the string. If there are less than n characters available in the string starting at the given position, or if n is -1 (default), the function returns all characters that are available from the specified position.

See also
first(), last(), sliced(), chopped(), chop(), truncate()

Definition at line 4994 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ normalized()

QString QString::normalized ( QString::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.

Definition at line 7919 of file qstring.cpp.

Here is the caller graph for this function:

◆ number() [1/7]

QString QString::number ( double  n,
char  format = 'g',
int  precision = 6 
)
static

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.

See also
setNum(), QLocale::toString(), QLocale::FloatingPointPrecisionOption, {Number Formats}

Definition at line 7596 of file qstring.cpp.

◆ number() [2/7]

QString QString::number ( int  n,
int  base = 10 
)
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 7538 of file qstring.cpp.

Here is the caller graph for this function:

◆ number() [3/7]

QString QString::number ( long  n,
int  base = 10 
)
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.

See also
setNum()

Definition at line 7520 of file qstring.cpp.

Here is the call graph for this function:

◆ number() [4/7]

QString QString::number ( qlonglong  n,
int  base = 10 
)
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 7554 of file qstring.cpp.

Here is the call graph for this function:

◆ number() [5/7]

QString QString::number ( qulonglong  n,
int  base = 10 
)
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 7573 of file qstring.cpp.

Here is the call graph for this function:

◆ number() [6/7]

QString QString::number ( uint  n,
int  base = 10 
)
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 7546 of file qstring.cpp.

Here is the call graph for this function:

◆ number() [7/7]

QString QString::number ( ulong  n,
int  base = 10 
)
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 7530 of file qstring.cpp.

Here is the call graph for this function:

◆ operator!=() [1/2]

bool QString::operator!= ( const char *  s) const
inline

Definition at line 1361 of file qstring.h.

Here is the call graph for this function:

◆ operator!=() [2/2]

QT_ASCII_CAST_WARN bool QString::operator!= ( const QByteArray s) const
inline

Definition at line 1405 of file qstring.h.

Here is the call graph for this function:

◆ operator+=() [1/6]

QT_ASCII_CAST_WARN QString& QString::operator+= ( const char *  s)
inline

Definition at line 992 of file qstring.h.

Here is the call graph for this function:

◆ operator+=() [2/6]

QT_ASCII_CAST_WARN QString& QString::operator+= ( const QByteArray s)
inline

Definition at line 994 of file qstring.h.

Here is the call graph for this function:

◆ operator+=() [3/6]

QString & QString::operator+= ( const QString other)
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.

See also
append(), prepend()

Definition at line 667 of file qstring.h.

Here is the call graph for this function:

◆ operator+=() [4/6]

QString& QString::operator+= ( QChar  c)
inline

Definition at line 664 of file qstring.h.

Here is the call graph for this function:

◆ operator+=() [5/6]

QString& QString::operator+= ( QLatin1String  s)
inline

Definition at line 670 of file qstring.h.

Here is the call graph for this function:

◆ operator+=() [6/6]

QString& QString::operator+= ( QStringView  v)
inline

Definition at line 669 of file qstring.h.

Here is the call graph for this function:

◆ operator<() [1/2]

bool QString::operator< ( const char *  s) const
inline

Definition at line 1363 of file qstring.h.

Here is the call graph for this function:

◆ operator<() [2/2]

QT_ASCII_CAST_WARN bool QString::operator< ( const QByteArray s) const
inline

Definition at line 1407 of file qstring.h.

Here is the call graph for this function:

◆ operator<=() [1/2]

bool QString::operator<= ( const char *  s) const
inline

Definition at line 1367 of file qstring.h.

Here is the call graph for this function:

◆ operator<=() [2/2]

QT_ASCII_CAST_WARN bool QString::operator<= ( const QByteArray s) const
inline

Definition at line 1411 of file qstring.h.

Here is the call graph for this function:

◆ operator=() [1/5]

QT_ASCII_CAST_WARN QString& QString::operator= ( const char *  ch)
inline

Definition at line 974 of file qstring.h.

Here is the call graph for this function:

◆ operator=() [2/5]

QT_ASCII_CAST_WARN QString& QString::operator= ( const QByteArray a)
inline

Definition at line 976 of file qstring.h.

Here is the call graph for this function:

◆ operator=() [3/5]

QString & QString::operator= ( const QString other)
noexcept

Assigns other to this string and returns a reference to this string.

Definition at line 2822 of file qstring.cpp.

Here is the call graph for this function:

◆ operator=() [4/5]

QString & QString::operator= ( QChar  c)

Definition at line 2886 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [5/5]

QString & QString::operator= ( QLatin1String  latin1)

Definition at line 2842 of file qstring.cpp.

Here is the call graph for this function:

◆ operator==() [1/2]

bool QString::operator== ( const char *  s) const
inline

Definition at line 1359 of file qstring.h.

Here is the call graph for this function:

◆ operator==() [2/2]

QT_ASCII_CAST_WARN bool QString::operator== ( const QByteArray s) const
inline

Definition at line 1403 of file qstring.h.

Here is the call graph for this function:

◆ operator>() [1/2]

bool QString::operator> ( const char *  s) const
inline

Definition at line 1365 of file qstring.h.

Here is the call graph for this function:

◆ operator>() [2/2]

QT_ASCII_CAST_WARN bool QString::operator> ( const QByteArray s) const
inline

Definition at line 1409 of file qstring.h.

Here is the call graph for this function:

◆ operator>=() [1/2]

bool QString::operator>= ( const char *  s) const
inline

Definition at line 1369 of file qstring.h.

Here is the call graph for this function:

◆ operator>=() [2/2]

QT_ASCII_CAST_WARN bool QString::operator>= ( const QByteArray s) const
inline

Definition at line 1413 of file qstring.h.

Here is the call graph for this function:

◆ operator[]() [1/2]

QChar & QString::operator[] ( qsizetype  position)
inline

Returns the character at the specified position in the string as a modifiable reference.

Example:

See also
at()

Definition at line 1327 of file qstring.h.

Here is the call graph for this function:

◆ operator[]() [2/2]

const QChar QString::operator[] ( qsizetype  i) const
inline

Definition at line 1214 of file qstring.h.

Here is the call graph for this function:

◆ prepend() [1/7]

QT_ASCII_CAST_WARN QString& QString::prepend ( const char *  s)
inline

Definition at line 980 of file qstring.h.

Here is the call graph for this function:

◆ prepend() [2/7]

QT_ASCII_CAST_WARN QString& QString::prepend ( const QByteArray s)
inline

Definition at line 982 of file qstring.h.

Here is the call graph for this function:

◆ prepend() [3/7]

QString& QString::prepend ( const QChar uc,
qsizetype  len 
)
inline

Definition at line 657 of file qstring.h.

Here is the call graph for this function:

◆ prepend() [4/7]

QString & QString::prepend ( const QString str)
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:

See also
append(), insert()

Definition at line 659 of file qstring.h.

Here is the call graph for this function:

◆ prepend() [5/7]

QString& QString::prepend ( QChar  c)
inline

Definition at line 656 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepend() [6/7]

QString& QString::prepend ( QLatin1String  s)
inline

Definition at line 662 of file qstring.h.

Here is the call graph for this function:

◆ prepend() [7/7]

QString& QString::prepend ( QStringView  v)
inline

Definition at line 661 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_back() [1/2]

void QString::push_back ( const QString other)
inline

This function is provided for STL compatibility, appending the given other string onto the end of this string. It is equivalent to append(other).

See also
append()

Definition at line 1055 of file qstring.h.

Here is the call graph for this function:

◆ push_back() [2/2]

void QString::push_back ( QChar  ch)
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.

Definition at line 1054 of file qstring.h.

Here is the call graph for this function:

◆ push_front() [1/2]

void QString::push_front ( const QString other)
inline

This function is provided for STL compatibility, prepending the given other string to the beginning of this string. It is equivalent to prepend(other).

See also
prepend()

Definition at line 1057 of file qstring.h.

Here is the call graph for this function:

◆ push_front() [2/2]

void QString::push_front ( QChar  ch)
inline

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.

Definition at line 1056 of file qstring.h.

Here is the call graph for this function:

◆ rbegin() [1/2]

QString::reverse_iterator QString::rbegin ( )
inline
Since
5.6

Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first character in the string, in reverse order.

iterator-invalidation-func-desc

See also
begin(), crbegin(), rend()

Definition at line 1039 of file qstring.h.

Here is the call graph for this function:

◆ rbegin() [2/2]

QString::const_reverse_iterator QString::rbegin ( ) const
inline
Since
5.6 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 1041 of file qstring.h.

Here is the call graph for this function:

◆ remove() [1/4]

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.

If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

This is the same as replace(str, "", cs).

shrinking-erase

See also
replace()

Definition at line 3310 of file qstring.cpp.

Here is the call graph for this function:

◆ remove() [2/4]

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.

If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

Example:

This is the same as replace(ch, "", cs).

shrinking-erase

See also
replace()

Definition at line 3359 of file qstring.cpp.

Here is the call graph for this function:

◆ remove() [3/4]

QString & QString::remove ( QLatin1String  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
Since
5.11 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Removes every occurrence of the given str string in this string, and returns a reference to this string.

If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

This is the same as replace(str, "", cs).

shrinking-erase

See also
replace()

Definition at line 3336 of file qstring.cpp.

◆ remove() [4/4]

QString & QString::remove ( qsizetype  position,
qsizetype  n 
)

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.

! [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]

See also
insert(), replace()

Definition at line 3252 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeIf()

template<typename Predicate >
template< typename Predicate > QString & QString::removeIf ( Predicate  pred)
inline
Since
6.1

Removes all elements for which the predicate pred returns true from the string. Returns a reference to the string.

See also
remove()

Definition at line 677 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rend() [1/2]

QString::reverse_iterator QString::rend ( )
inline
Since
5.6

Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing just after the last character in the string, in reverse order.

iterator-invalidation-func-desc

See also
end(), crend(), rbegin()

Definition at line 1040 of file qstring.h.

Here is the call graph for this function:

◆ rend() [2/2]

QString::const_reverse_iterator QString::rend ( ) const
inline
Since
5.6 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 1042 of file qstring.h.

Here is the call graph for this function:

◆ repeated()

QString QString::repeated ( qsizetype  times) const
Since
4.5

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 7818 of file qstring.cpp.

Here is the call graph for this function:

◆ replace() [1/11]

QString & QString::replace ( const QChar before,
qsizetype  blen,
const QChar after,
qsizetype  alen,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Definition at line 3573 of file qstring.cpp.

◆ replace() [2/11]

QString & QString::replace ( const QString before,
const QString after,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Definition at line 3473 of file qstring.cpp.

Here is the call graph for this function:

◆ replace() [3/11]

QString & QString::replace ( const QString before,
QLatin1String  after,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Definition at line 3777 of file qstring.cpp.

Here is the call graph for this function:

◆ replace() [4/11]

QString & QString::replace ( QChar  before,
QChar  after,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Definition at line 3693 of file qstring.cpp.

Here is the call graph for this function:

◆ replace() [5/11]

QString & QString::replace ( QChar  c,
const QString after,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Definition at line 3642 of file qstring.cpp.

Here is the call graph for this function:

◆ replace() [6/11]

QString & QString::replace ( QChar  c,
QLatin1String  after,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Definition at line 3797 of file qstring.cpp.

Here is the call graph for this function:

◆ replace() [7/11]

QString & QString::replace ( QLatin1String  before,
const QString after,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Definition at line 3757 of file qstring.cpp.

Here is the call graph for this function:

◆ replace() [8/11]

QString & QString::replace ( QLatin1String  before,
QLatin1String  after,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Definition at line 3734 of file qstring.cpp.

Here is the call graph for this function:

◆ replace() [9/11]

QString & QString::replace ( qsizetype  i,
qsizetype  len,
const QChar s,
qsizetype  slen 
)

Definition at line 3431 of file qstring.cpp.

Here is the call graph for this function:

◆ replace() [10/11]

QString & QString::replace ( qsizetype  position,
qsizetype  n,
const QString after 
)

Replaces n characters beginning at index position with the string after and returns a reference to this string.

Note
If the specified position index is within the string, but position + n goes outside the strings range, then n will be adjusted to stop at the end of the string.

Example:

See also
insert(), remove()

Definition at line 3419 of file qstring.cpp.

Here is the call graph for this function:

◆ replace() [11/11]

QString & QString::replace ( qsizetype  i,
qsizetype  len,
QChar  after 
)

Definition at line 3450 of file qstring.cpp.

Here is the caller graph for this function:

◆ reserve()

void QString::reserve ( qsizetype  size)
inline

Ensures the string has space for at least size characters.

If you know in advance how large the string will be, you can call this function to save repeated reallocation in the course of 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 really need, which 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.

Warning
reserve() reserves memory but does not change the size of the string. Accessing data beyond the end of the string is undefined behavior. If you need to access memory beyond the current end of the string, use resize().

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:

See also
squeeze(), capacity(), resize()

Definition at line 1307 of file qstring.h.

Here is the caller graph for this function:

◆ resize() [1/2]

void QString::resize ( qsizetype  size)

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.

Note
While resize() will grow the capacity if needed, it never shrinks capacity. To shed excess capacity, use squeeze().

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.

See also
truncate(), reserve(), squeeze()

Definition at line 2670 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize() [2/2]

void QString::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.

Since
5.7

Unlike \l {QString::}{resize(qsizetype)}, this overload initializes the new characters to fillChar:

Definition at line 2693 of file qstring.cpp.

Here is the call graph for this function:

◆ right()

QString QString::right ( qsizetype  n) const

Returns a substring that contains the n rightmost characters of the string.

If you know that n cannot be out of bounds, use last() instead in new code, because it is faster.

The entire string is returned if n is greater than or equal to size(), or less than zero.

See also
endsWith(), last(), first(), sliced(), chopped(), chop(), truncate()

Definition at line 4970 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rightJustified()

QString QString::rightJustified ( qsizetype  width,
QChar  fill = QLatin1Char(' '),
bool  truncate = false 
) const

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.

See also
leftJustified()

Definition at line 6557 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ section() [1/2]

QString QString::section ( const QString in_sep,
qsizetype  start,
qsizetype  end = -1,
SectionFlags  flags = SectionDefault 
) const

Definition at line 4777 of file qstring.cpp.

Here is the call graph for this function:

◆ section() [2/2]

QString QString::section ( QChar  sep,
qsizetype  start,
qsizetype  end = -1,
SectionFlags  flags = SectionDefault 
) const
inline

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.

See also
split()

Definition at line 1272 of file qstring.h.

Here is the caller graph for this function:

◆ setNum() [1/10]

QString & QString::setNum ( double  n,
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.

See also
number(), QLocale::FloatingPointPrecisionOption, {Number Formats}

Definition at line 7480 of file qstring.cpp.

Here is the call graph for this function:

◆ setNum() [2/10]

QString & QString::setNum ( float  n,
char  format = 'g',
int  precision = 6 
)
inline

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.

See also
number()

Definition at line 1257 of file qstring.h.

◆ setNum() [3/10]

QString & QString::setNum ( int  n,
int  base = 10 
)
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.

See also
number()

Definition at line 1249 of file qstring.h.

◆ setNum() [4/10]

QString & QString::setNum ( long  n,
int  base = 10 
)
inline

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 1253 of file qstring.h.

◆ setNum() [5/10]

QString & QString::setNum ( qlonglong  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 7448 of file qstring.cpp.

Here is the call graph for this function:

◆ setNum() [6/10]

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 7456 of file qstring.cpp.

Here is the call graph for this function:

◆ setNum() [7/10]

QString & QString::setNum ( short  n,
int  base = 10 
)
inline

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 1245 of file qstring.h.

Here is the caller graph for this function:

◆ setNum() [8/10]

QString & QString::setNum ( uint  n,
int  base = 10 
)
inline

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 1251 of file qstring.h.

◆ setNum() [9/10]

QString & QString::setNum ( ulong  n,
int  base = 10 
)
inline

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 1255 of file qstring.h.

◆ setNum() [10/10]

QString & QString::setNum ( ushort  n,
int  base = 10 
)
inline

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 1247 of file qstring.h.

◆ setRawData()

QString & QString::setRawData ( const QChar unicode,
qsizetype  size 
)
Since
4.7

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.

See also
fromRawData()

Definition at line 8957 of file qstring.cpp.

Here is the call graph for this function:

◆ setUnicode()

QString & QString::setUnicode ( const QChar unicode,
qsizetype  size 
)

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.

See also
unicode(), setUtf16()

Definition at line 5713 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUtf16()

QString & QString::setUtf16 ( const ushort unicode,
qsizetype  size 
)
inline

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.

See also
utf16(), setUnicode()

Definition at line 1325 of file qstring.h.

◆ shrink_to_fit()

void QString::shrink_to_fit ( )
inline
Since
5.10

This function is provided for STL compatibility. It is equivalent to squeeze().

See also
squeeze()

Definition at line 1058 of file qstring.h.

◆ simplified() [1/2]

QString QString::simplified ( ) &&
inline

Definition at line 629 of file qstring.h.

◆ simplified() [2/2]

QString QString::simplified ( ) const &
inline

Definition at line 627 of file qstring.h.

Here is the caller graph for this function:

◆ size()

qsizetype QString::size ( ) const
inline

Returns the number of characters in this string.

The last character in the string is at position size() - 1.

Example:

See also
isEmpty(), resize()

Definition at line 413 of file qstring.h.

Here is the caller graph for this function:

◆ sliced() [1/2]

QString QString::sliced ( qsizetype  pos) const
inline
Since
6.0 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns a string that contains the portion of this string starting at position pos and extending to its end.

Note
The behavior is undefined when pos < 0 or pos > size().
See also
first(), last(), sliced(), chopped(), chop(), truncate()

Definition at line 580 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sliced() [2/2]

QString QString::sliced ( qsizetype  pos,
qsizetype  n 
) const
inline
Since
6.0

Returns a string that contains n characters of this string, starting at position pos.

Note
The behavior is undefined when pos < 0, n < 0, or pos + n > size().
See also
first(), last(), chopped(), chop(), truncate()

Definition at line 582 of file qstring.h.

Here is the call graph for this function:

◆ split() [1/3]

QStringList QString::split ( const QRegularExpression sep,
Qt::SplitBehavior  behavior = Qt::KeepEmptyParts 
) const

◆ split() [2/3]

QStringList QString::split ( const QString sep,
Qt::SplitBehavior  behavior = Qt::KeepEmptyParts,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Splits the string into substrings wherever sep occurs, and returns the list of those strings. 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:

See also
QStringList::join(), section()
Since
5.14

Definition at line 7672 of file qstring.cpp.

Here is the caller graph for this function:

◆ split() [3/3]

QStringList QString::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.

Since
5.14

Definition at line 7681 of file qstring.cpp.

◆ squeeze()

void QString::squeeze ( )
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.

See also
reserve(), capacity()

Definition at line 1315 of file qstring.h.

Here is the caller graph for this function:

◆ startsWith() [1/4]

bool QString::startsWith ( const QString s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Returns true if the string starts with s; otherwise returns false.

If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

See also
endsWith()

Definition at line 5092 of file qstring.cpp.

Here is the caller graph for this function:

◆ startsWith() [2/4]

bool QString::startsWith ( QChar  c,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Definition at line 5112 of file qstring.cpp.

◆ startsWith() [3/4]

bool QString::startsWith ( QLatin1String  s,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Definition at line 5101 of file qstring.cpp.

◆ startsWith() [4/4]

bool QString::startsWith ( QStringView  str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inlinenoexcept
Since
5.10 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns true if the string starts with the string view str; otherwise returns false.

If cs is Qt::CaseSensitive (default), the search is case-sensitive; otherwise the search is case insensitive.

See also
endsWith()

Definition at line 591 of file qstring.h.

Here is the call graph for this function:

◆ swap()

void QString::swap ( QString other)
inlinenoexcept
Since
4.8

Swaps string other with this string. This operation is very fast and never fails.

Definition at line 412 of file qstring.h.

Here is the call graph for this function:

◆ toCaseFolded() [1/2]

QString QString::toCaseFolded ( ) &&
inline

Definition at line 621 of file qstring.h.

◆ toCaseFolded() [2/2]

QString QString::toCaseFolded ( ) const &
inline

Definition at line 619 of file qstring.h.

◆ toDouble()

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.

Warning
The QString content may only contain valid numerical characters which includes the plus/minus sign, the character e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.

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.

See also
number(), QLocale::setDefault(), QLocale::toDouble(), trimmed()

Definition at line 7374 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toFloat()

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.

Warning
The QString content may only contain valid numerical characters which includes the plus/minus sign, the character e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.

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.

See also
number(), toDouble(), toInt(), QLocale::toFloat(), trimmed()

Definition at line 7409 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toHtmlEscaped()

QString QString::toHtmlEscaped ( ) const
Since
5.0

Converts a plain text string to an HTML string with HTML metacharacters {<}, {>}, {&}, and {"} replaced by HTML entities.

Example:

Definition at line 10705 of file qstring.cpp.

Here is the call graph for this function:

◆ toInt()

int QString::toInt ( bool *  ok = nullptr,
int  base = 10 
) const
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 "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.

See also
number(), toUInt(), toDouble(), QLocale::toInt()

Definition at line 848 of file qstring.h.

Here is the caller graph for this function:

◆ tokenize() [1/3]

template<typename Needle , typename... Flags>
auto QString::tokenize ( Needle &&  needle,
Flags...  flags 
) && -> decltype(qTokenize(std::move(*this), std::forward<Needle>(needle), flags...))
inlinenoexcept

Definition at line 726 of file qstring.h.

Here is the call graph for this function:

◆ tokenize() [2/3]

template<typename Needle , typename... Flags>
auto QString::tokenize ( Needle &&  needle,
Flags...  flags 
) const && -> decltype(qTokenize(std::move(*this), std::forward<Needle>(needle), flags...))
inlinenoexcept

Definition at line 720 of file qstring.h.

Here is the call graph for this function:

◆ tokenize() [3/3]

template<typename Needle , typename... Flags>
auto QString::tokenize ( Needle &&  needle,
Flags...  flags 
) const & -> decltype(qTokenize(*this, std::forward<Needle>(needle), flags...))
inlinenoexcept

Definition at line 714 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toLatin1() [1/2]

QByteArray QString::toLatin1 ( ) &&
inline

Definition at line 747 of file qstring.h.

◆ toLatin1() [2/2]

QByteArray QString::toLatin1 ( ) const &
inline

Definition at line 745 of file qstring.h.

Here is the caller graph for this function:

◆ toLocal8Bit() [1/2]

QByteArray QString::toLocal8Bit ( ) &&
inline

Definition at line 755 of file qstring.h.

Here is the call graph for this function:

◆ toLocal8Bit() [2/2]

QByteArray QString::toLocal8Bit ( ) const &
inline

Definition at line 753 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toLong()

long QString::toLong ( bool *  ok = nullptr,
int  base = 10 
) const
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 "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.

See also
number(), toULong(), toInt(), QLocale::toInt()

Definition at line 852 of file qstring.h.

Here is the caller graph for this function:

◆ toLongLong()

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

See also
number(), toULongLong(), toInt(), QLocale::toLongLong()

Definition at line 7127 of file qstring.cpp.

Here is the caller graph for this function:

◆ toLower() [1/2]

QString QString::toLower ( ) &&
inline

Definition at line 613 of file qstring.h.

◆ toLower() [2/2]

QString QString::toLower ( ) const &
inline

Definition at line 611 of file qstring.h.

Here is the caller graph for this function:

◆ toShort()

short QString::toShort ( bool *  ok = nullptr,
int  base = 10 
) const
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 "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.

See also
number(), toUShort(), toInt(), QLocale::toShort()

Definition at line 844 of file qstring.h.

Here is the caller graph for this function:

◆ toStdString()

std::string QString::toStdString ( ) const
inline

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.

See also
toLatin1(), toUtf8(), toLocal8Bit(), QByteArray::toStdString()

Definition at line 1449 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toStdU16String()

std::u16string QString::toStdU16String ( ) const
inline
Since
5.5

Returns a std::u16string object with the data contained in this QString. The Unicode data is the same as returned by the utf16() method.

See also
utf16(), toStdWString(), toStdU32String()

Definition at line 1469 of file qstring.h.

Here is the call graph for this function:

◆ toStdU32String()

std::u32string QString::toStdU32String ( ) const
inline
Since
5.5

Returns a std::u32string object with the data contained in this QString. The Unicode data is the same as returned by the toUcs4() method.

See also
toUcs4(), toStdWString(), toStdU16String()

Definition at line 1475 of file qstring.h.

◆ toStdWString()

std::wstring QString::toStdWString ( ) const
inline

Returns a std::wstring object with the data contained in this QString. The std::wstring is encoded in utf16 on platforms where wchar_t is 2 bytes wide (e.g. windows) and in ucs4 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.

See also
utf16(), toLatin1(), toUtf8(), toLocal8Bit(), toStdU16String(), toStdU32String()

Definition at line 1455 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toUcs4()

QList< uint > QString::toUcs4 ( ) const
Since
4.2

Returns a UCS-4/UTF-32 representation of the string as a QList<uint>.

UCS-4 is a Unicode codec and therefore it is lossless. All characters from this string will be encoded in UCS-4. Any invalid sequence of code units in this string is replaced by the Unicode's replacement character (QChar::ReplacementCharacter, which corresponds to {U+FFFD}).

The returned list is not \0'-terminated.

See also
fromUtf8(), toUtf8(), toLatin1(), toLocal8Bit(), QStringEncoder, fromUcs4(), toWCharArray()

Definition at line 5440 of file qstring.cpp.

◆ toUInt()

uint QString::toUInt ( bool *  ok = nullptr,
int  base = 10 
) const
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 "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.

See also
number(), toInt(), QLocale::toUInt()

Definition at line 850 of file qstring.h.

Here is the caller graph for this function:

◆ toULong()

ulong QString::toULong ( bool *  ok = nullptr,
int  base = 10 
) const
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 "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.

See also
number(), QLocale::toUInt()

Definition at line 854 of file qstring.h.

Here is the caller graph for this function:

◆ toULongLong()

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

See also
number(), toLongLong(), QLocale::toULongLong()

Definition at line 7169 of file qstring.cpp.

Here is the caller graph for this function:

◆ toUpper() [1/2]

QString QString::toUpper ( ) &&
inline

Definition at line 617 of file qstring.h.

◆ toUpper() [2/2]

QString QString::toUpper ( ) const &
inline

Definition at line 615 of file qstring.h.

Here is the caller graph for this function:

◆ toUShort()

ushort QString::toUShort ( bool *  ok = nullptr,
int  base = 10 
) const
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; 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.

See also
number(), toShort(), QLocale::toUShort()

Definition at line 846 of file qstring.h.

Here is the caller graph for this function:

◆ toUtf8() [1/2]

QByteArray QString::toUtf8 ( ) &&
inline

Definition at line 751 of file qstring.h.

◆ toUtf8() [2/2]

QByteArray QString::toUtf8 ( ) const &
inline

Definition at line 749 of file qstring.h.

Here is the caller graph for this function:

◆ toWCharArray()

qsizetype QString::toWCharArray ( wchar_t *  array) const
inline
Since
4.2

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 UCS-4 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.

Note
This function does not append a null character to the array.
See also
utf16(), toUcs4(), toLatin1(), toUtf8(), toLocal8Bit(), toStdWString(), QStringView::toWCharArray()
Here is the caller graph for this function:

◆ trimmed() [1/2]

QString QString::trimmed ( ) &&
inline

Definition at line 625 of file qstring.h.

◆ trimmed() [2/2]

QString QString::trimmed ( ) const &
inline

Definition at line 623 of file qstring.h.

Here is the caller graph for this function:

◆ truncate()

void QString::truncate ( qsizetype  position)

Truncates the string at the given position index.

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.

See also
chop(), resize(), first(), QStringView::truncate()

Definition at line 5934 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unicode()

const QChar * QString::unicode ( ) const
inline

Returns a Unicode representation of the string. The result remains valid until the string is modified.

Note
The returned string may not be '\0'-terminated. Use size() to determine the length of the array.
See also
utf16(), fromRawData()

Definition at line 1218 of file qstring.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf16()

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.

See also
unicode()

Definition at line 6491 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vasprintf()

QString QString::vasprintf ( const char *  cformat,
va_list  ap 
)
static
Since
5.5

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.

See also
asprintf()

Definition at line 6853 of file qstring.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ erase()

template< typename T > qsizetype erase ( QString s,
const T t 
)
related
Since
6.1

Removes all elements that compare equal to t from the string s. Returns the number of elements removed, if any.

See also
erase_if

Definition at line 1560 of file qstring.h.

Here is the call graph for this function:

◆ erase_if()

template< typename Predicate > qsizetype erase_if ( QString s,
Predicate  pred 
)
related
Since
6.1

Removes all elements for which the predicate pred returns true from the string s. Returns the number of elements removed, if any.

See also
erase

Definition at line 1566 of file qstring.h.

Here is the call graph for this function:

◆ localeAwareCompare()

localeAwareCompare ( )
related

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

Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string.

The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.

Same as {localeAwareCompare(*this, other)}.

See also
{Comparing Strings}
Here is the caller graph for this function:

◆ operator!= [1/10]

bool QString::operator!= ( const char *  s1,
const QString s2 
)
friend

Returns true if s1 is not equal to s2; otherwise returns false.

For s1 != 0, this is equivalent to {compare(} s1, s2 {) != 0}. Note that no string is equal to s1 being 0.

Definition at line 1013 of file qstring.h.

◆ operator!= [2/10]

bool operator!= ( const char16_t *  s1,
const QString s2 
)
friend

Definition at line 928 of file qstring.h.

◆ operator!= [3/10]

bool operator!= ( const QString lhs,
QChar  rhs 
)
friend

Definition at line 947 of file qstring.h.

◆ operator!= [4/10]

bool operator!= ( const QString s1,
const char16_t *  s2 
)
friend

Definition at line 921 of file qstring.h.

◆ operator!= [5/10]

bool QString::operator!= ( const QString s1,
const QString s2 
)
friend

Returns true if string s1 is not equal to string s2; otherwise returns false.

See also
{Comparing Strings}

Definition at line 885 of file qstring.h.

◆ operator!= [6/10]

bool operator!= ( const QString s1,
QLatin1String  s2 
)
friend

Definition at line 895 of file qstring.h.

◆ operator!= [7/10]

bool operator!= ( const QString s1,
std::nullptr_t   
)
friend

Definition at line 908 of file qstring.h.

◆ operator!= [8/10]

bool operator!= ( QChar  lhs,
const QString rhs 
)
friend

Definition at line 942 of file qstring.h.

◆ operator!= [9/10]

bool operator!= ( QLatin1String  s1,
const QString s2 
)
friend

Definition at line 902 of file qstring.h.

◆ operator!= [10/10]

bool operator!= ( std::nullptr_t  ,
const QString s2 
)
friend

Definition at line 914 of file qstring.h.

◆ operator""_qs()

operator""_qs ( const char16_t *  str,
size_t  size 
)
related

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

Note
QLatin1String can still be more efficient than QStringLiteral when the string is passed to a function that has an overload taking QLatin1String and this overload avoids conversion to QString. For instance, QString::operator==() can compare to a QLatin1String directly:
Note
Some compilers have bugs encoding strings containing characters outside the US-ASCII character set. Make sure you prefix your string with {u} in those cases. It is optional otherwise.
See also
QByteArrayLiteral
Since
6.2

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:

auto str = u"hello"_qs;
small capitals from c petite p scientific f u
Definition: afcover.h:88
QString str
[2]
See also
QStringLiteral, QtLiterals::operator""_qba(const char *str, size_t size)

Definition at line 1572 of file qstring.h.

◆ operator+() [1/3]

const QString operator+ ( const char *  s1,
const QString s2 
)
related

Returns a string which is the result of concatenating s1 and s2 (s1 is converted to Unicode using the QString::fromUtf8() function).

See also
QString::fromUtf8()

Definition at line 1440 of file qstring.h.

Here is the call graph for this function:

◆ operator+() [2/3]

const QString operator+ ( const QString s1,
const char *  s2 
)
related

Returns a string which is the result of concatenating s1 and s2 (s2 is converted to Unicode using the QString::fromUtf8() function).

See also
QString::fromUtf8()

Definition at line 1438 of file qstring.h.

Here is the call graph for this function:

◆ operator+() [3/3]

const QString operator+ ( const QString s1,
const QString s2 
)
related

Returns a string which is the result of concatenating s1 and s2.

Definition at line 1431 of file qstring.h.

◆ operator< [1/10]

bool QString::operator< ( const char *  s1,
const QString s2 
)
friend

Returns true if s1 is lexically less than s2; otherwise returns false. For s1 != 0, this is equivalent to {compare(s1, s2) < 0}.

See also
{Comparing Strings}

Definition at line 1015 of file qstring.h.

◆ operator< [2/10]

bool operator< ( const char16_t *  s1,
const QString s2 
)
friend

Definition at line 929 of file qstring.h.

◆ operator< [3/10]

bool operator< ( const QString ,
std::nullptr_t   
)
friend

Definition at line 909 of file qstring.h.

◆ operator< [4/10]

bool operator< ( const QString lhs,
QChar  rhs 
)
friend

Definition at line 948 of file qstring.h.

◆ operator< [5/10]

bool operator< ( const QString s1,
const char16_t *  s2 
)
friend

Definition at line 922 of file qstring.h.

◆ operator< [6/10]

bool operator< ( const QString s1,
const QString s2 
)
friend

Definition at line 882 of file qstring.h.

◆ operator< [7/10]

bool operator< ( const QString s1,
QLatin1String  s2 
)
friend

Definition at line 891 of file qstring.h.

◆ operator< [8/10]

bool operator< ( QChar  lhs,
const QString rhs 
)
friend

Definition at line 937 of file qstring.h.

◆ operator< [9/10]

bool operator< ( QLatin1String  s1,
const QString s2 
)
friend

Definition at line 900 of file qstring.h.

◆ operator< [10/10]

bool operator< ( std::nullptr_t  ,
const QString s2 
)
friend

Definition at line 915 of file qstring.h.

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QString string 
)
related

Writes the given string to the specified stream.

See also
{Serializing Qt Data Types}

Definition at line 10084 of file qstring.cpp.

Here is the call graph for this function:

◆ operator<= [1/10]

bool QString::operator<= ( const char *  s1,
const QString s2 
)
friend

Returns true if s1 is lexically less than or equal to s2; otherwise returns false. For s1 != 0, this is equivalent to {compare(s1, s2) <= 0}.

See also
{Comparing Strings}

Definition at line 1019 of file qstring.h.

◆ operator<= [2/10]

bool operator<= ( const char16_t *  s1,
const QString s2 
)
friend

Definition at line 931 of file qstring.h.

◆ operator<= [3/10]

bool operator<= ( const QString lhs,
QChar  rhs 
)
friend

Definition at line 950 of file qstring.h.

◆ operator<= [4/10]

bool operator<= ( const QString s1,
const char16_t *  s2 
)
friend

Definition at line 924 of file qstring.h.

◆ operator<= [5/10]

bool QString::operator<= ( const QString s1,
const QString s2 
)
friend

Returns true if string s1 is lexically less than or equal to string s2; otherwise returns false.

See also
{Comparing Strings}

Definition at line 886 of file qstring.h.

◆ operator<= [6/10]

bool operator<= ( const QString s1,
QLatin1String  s2 
)
friend

Definition at line 896 of file qstring.h.

◆ operator<= [7/10]

bool operator<= ( const QString s1,
std::nullptr_t   
)
friend

Definition at line 911 of file qstring.h.

◆ operator<= [8/10]

bool operator<= ( QChar  lhs,
const QString rhs 
)
friend

Definition at line 943 of file qstring.h.

◆ operator<= [9/10]

bool operator<= ( QLatin1String  s1,
const QString s2 
)
friend

Definition at line 903 of file qstring.h.

◆ operator<= [10/10]

bool operator<= ( std::nullptr_t  ,
const QString s2 
)
friend

Definition at line 917 of file qstring.h.

◆ operator== [1/10]

QT_ASCII_CAST_WARN friend bool operator== ( const char *  s1,
const QString s2 
)
friend

Definition at line 1011 of file qstring.h.

◆ operator== [2/10]

bool operator== ( const char16_t *  s1,
const QString s2 
)
friend

Definition at line 927 of file qstring.h.

◆ operator== [3/10]

bool operator== ( const QString lhs,
QChar  rhs 
)
friend

Definition at line 946 of file qstring.h.

◆ operator== [4/10]

bool operator== ( const QString s1,
const char16_t *  s2 
)
friend

Definition at line 920 of file qstring.h.

◆ operator== [5/10]

bool operator== ( const QString s1,
const QString s2 
)
friend

Definition at line 880 of file qstring.h.

◆ operator== [6/10]

bool operator== ( const QString s1,
QLatin1String  s2 
)
friend

Definition at line 889 of file qstring.h.

◆ operator== [7/10]

bool operator== ( const QString s1,
std::nullptr_t   
)
friend

Definition at line 907 of file qstring.h.

◆ operator== [8/10]

bool operator== ( QChar  lhs,
const QString rhs 
)
friend

Definition at line 935 of file qstring.h.

◆ operator== [9/10]

bool operator== ( QLatin1String  s1,
const QString s2 
)
friend

Definition at line 899 of file qstring.h.

◆ operator== [10/10]

bool operator== ( std::nullptr_t  ,
const QString s2 
)
friend

Definition at line 913 of file qstring.h.

◆ operator> [1/10]

bool QString::operator> ( const char *  s1,
const QString s2 
)
friend

Returns true if s1 is lexically greater than s2; otherwise returns false. Equivalent to {compare(s1, s2) > 0}.

See also
{Comparing Strings}

Definition at line 1017 of file qstring.h.

◆ operator> [2/10]

bool operator> ( const char16_t *  s1,
const QString s2 
)
friend

Definition at line 930 of file qstring.h.

◆ operator> [3/10]

bool operator> ( const QString lhs,
QChar  rhs 
)
friend

Definition at line 949 of file qstring.h.

◆ operator> [4/10]

bool operator> ( const QString s1,
const char16_t *  s2 
)
friend

Definition at line 923 of file qstring.h.

◆ operator> [5/10]

bool QString::operator> ( const QString s1,
const QString s2 
)
friend

Returns true if string s1 is lexically greater than string s2; otherwise returns false.

See also
{Comparing Strings}

Definition at line 884 of file qstring.h.

◆ operator> [6/10]

bool operator> ( const QString s1,
QLatin1String  s2 
)
friend

Definition at line 893 of file qstring.h.

◆ operator> [7/10]

bool operator> ( const QString s1,
std::nullptr_t   
)
friend

Definition at line 910 of file qstring.h.

◆ operator> [8/10]

bool operator> ( QChar  lhs,
const QString rhs 
)
friend

Definition at line 939 of file qstring.h.

◆ operator> [9/10]

bool operator> ( QLatin1String  s1,
const QString s2 
)
friend

Definition at line 901 of file qstring.h.

◆ operator> [10/10]

bool operator> ( std::nullptr_t  ,
const QString s2 
)
friend

Definition at line 916 of file qstring.h.

◆ operator>= [1/10]

bool QString::operator>= ( const char *  s1,
const QString s2 
)
friend

Returns true if s1 is lexically greater than or equal to s2; otherwise returns false. For s1 != 0, this is equivalent to {compare(s1, s2) >= 0}.

See also
{Comparing Strings}

Definition at line 1021 of file qstring.h.

◆ operator>= [2/10]

bool operator>= ( const char16_t *  s1,
const QString s2 
)
friend

Definition at line 932 of file qstring.h.

◆ operator>= [3/10]

bool operator>= ( const QString ,
std::nullptr_t   
)
friend

Definition at line 912 of file qstring.h.

◆ operator>= [4/10]

bool operator>= ( const QString lhs,
QChar  rhs 
)
friend

Definition at line 951 of file qstring.h.

◆ operator>= [5/10]

bool operator>= ( const QString s1,
const char16_t *  s2 
)
friend

Definition at line 925 of file qstring.h.

◆ operator>= [6/10]

bool QString::operator>= ( const QString s1,
const QString s2 
)
friend

Returns true if string s1 is lexically greater than or equal to string s2; otherwise returns false.

See also
{Comparing Strings}

Definition at line 887 of file qstring.h.

◆ operator>= [7/10]

bool operator>= ( const QString s1,
QLatin1String  s2 
)
friend

Definition at line 897 of file qstring.h.

◆ operator>= [8/10]

bool operator>= ( QChar  lhs,
const QString rhs 
)
friend

Definition at line 944 of file qstring.h.

◆ operator>= [9/10]

bool operator>= ( QLatin1String  s1,
const QString s2 
)
friend

Definition at line 904 of file qstring.h.

◆ operator>= [10/10]

bool operator>= ( std::nullptr_t  ,
const QString s2 
)
friend

Definition at line 918 of file qstring.h.

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QString string 
)
related

Reads a string from the specified stream into the given string.

See also
{Serializing Qt Data Types}

Definition at line 10116 of file qstring.cpp.

Here is the call graph for this function:

◆ QAbstractConcatenable

friend struct QAbstractConcatenable
friend

Definition at line 1132 of file qstring.h.

◆ QByteArray

friend class QByteArray
friend

Definition at line 1131 of file qstring.h.

◆ QStringView

friend class QStringView
friend

Definition at line 1130 of file qstring.h.


The documentation for this class was generated from the following files: