QtBase
v6.3.1
|
The QString class provides a Unicode character string. More...
#include <qstring.h>
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 QChar * | iterator |
typedef const QChar * | const_iterator |
typedef iterator | Iterator |
typedef const_iterator | ConstIterator |
typedef std::reverse_iterator< iterator > | reverse_iterator |
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
typedef qsizetype | size_type |
typedef qptrdiff | difference_type |
typedef const QChar & | const_reference |
typedef QChar & | reference |
typedef QChar * | pointer |
typedef const QChar * | const_pointer |
typedef QChar | value_type |
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 | |
QDataStream & | operator<< (QDataStream &stream, const QString &string) |
QDataStream & | operator>> (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) |
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.
\macro QT_NO_CAST_FROM_ASCII
Disables automatic conversions from 8-bit strings ({char *}) to Unicode QStrings, as well as from 8-bit
{char} types (
{char} and
{unsigned char}) to QChar.
\macro QT_NO_CAST_TO_ASCII
Disables automatic conversion from QString to 8-bit strings ({char *}).
\macro QT_ASCII_CAST_WARNINGS
\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).
The QString::const_pointer typedef provides an STL-style const pointer to a QString element (QChar).
Qt-style synonym for QString::const_iterator.
typedef QStringPrivate QString::DataPointer |
Qt-style synonym for QString::iterator.
The QString::pointer typedef provides an STL-style pointer to a QString element (QChar).
This enum describes the various normalized forms of Unicode text.
\value NormalizationForm_D Canonical Decomposition \value NormalizationForm_C Canonical Decomposition followed by Canonical Composition \value NormalizationForm_KD Compatibility Decomposition \value NormalizationForm_KC Compatibility Decomposition followed by Canonical Composition
Enumerator | |
---|---|
NormalizationForm_D | |
NormalizationForm_C | |
NormalizationForm_KD | |
NormalizationForm_KC |
enum QString::SectionFlag |
This enum specifies flags that can be used to affect various aspects of the section() function's behavior with respect to separators and empty fields.
\value SectionDefault Empty fields are counted, leading and trailing separators are not included, and the separator is compared case sensitively.
\value SectionSkipEmpty Treat empty fields as if they don't exist, i.e. they are not considered as far as start and end are concerned.
\value SectionIncludeLeadingSep Include the leading separator (if any) in the result string.
\value SectionIncludeTrailingSep Include the trailing separator (if any) in the result string.
\value SectionCaseInsensitiveSeps Compare the separator case-insensitively.
Enumerator | |
---|---|
SectionDefault | |
SectionSkipEmpty | |
SectionIncludeLeadingSep | |
SectionIncludeTrailingSep | |
SectionCaseInsensitiveSeps |
|
inlineconstexprnoexcept |
Constructs a string initialized with the first size characters of the QChar array unicode.
If unicode is 0, a null string is constructed.
If size is negative, unicode is assumed to point to a \0'-terminated array and its length is determined dynamically. The terminating null character is not considered part of the string.
QString makes a deep copy of the string data. The unicode data is copied as is and the Byte Order Mark is preserved if present.
Definition at line 2503 of file qstring.cpp.
QString::QString | ( | QChar | ch | ) |
Constructs a string of size 1 containing the character ch.
Definition at line 2573 of file qstring.cpp.
Constructs a string of the given size with every character set to ch.
Definition at line 2530 of file qstring.cpp.
|
inline |
Constructs a copy of the Latin-1 string str.
Definition at line 1210 of file qstring.h.
Constructs a copy of other.
This operation takes \l{constant time}, because QString is \l{implicitly shared}. This makes returning a QString from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes \l{linear time}.
|
inlinedefaultnoexcept |
Move-constructs a QString instance, making it point at the same object that other was pointing to.
|
inline |
Constructs a string initialized with the 8-bit string str. The given const char pointer is converted to Unicode using the fromUtf8() function.
You can disable this constructor by defining \l QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.
{QString(const char (&ch)[N])} constructor instead. Using non-literal input, or input with embedded NUL characters, or non-7-bit characters is undefined in this case.
|
inline |
Constructs a string initialized with the byte array ba. The given byte array is converted to Unicode using fromUtf8().
You can disable this constructor by defining \l QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.
QString::QString | ( | qsizetype | size, |
Qt::Initialization | |||
) |
|
inlineexplicit |
|
inline |
Appends the string str onto the end of this string.
Example:
This is the same as using the insert() function:
The append() function is typically very fast (\l{constant time}), because QString preallocates extra space at the end of the string data so it can grow without reallocating the entire string each time.
Definition at line 3068 of file qstring.cpp.
Definition at line 3152 of file qstring.cpp.
QString & QString::append | ( | QLatin1String | s | ) |
|
inline |
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.
Definition at line 501 of file qstring.h.
QString QString::arg | ( | char | a, |
int | fieldWidth = 0 , |
||
QChar | fillChar = QLatin1Char(' ') |
||
) | const |
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.
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.
|
inline |
|
inline |
QString QString::arg | ( | QChar | a, |
int | fieldWidth = 0 , |
||
QChar | fillChar = QLatin1Char(' ') |
||
) | const |
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.
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.
QString QString::arg | ( | qlonglong | a, |
int | fieldwidth = 0 , |
||
int | base = 10 , |
||
QChar | fillChar = QLatin1Char(' ') |
||
) | const |
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.
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.
QString QString::arg | ( | qulonglong | a, |
int | fieldwidth = 0 , |
||
int | base = 10 , |
||
QChar | fillChar = QLatin1Char(' ') |
||
) | const |
Definition at line 8366 of file qstring.cpp.
|
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.
Definition at line 1267 of file qstring.h.
|
inline |
|
inline |
|
inline |
Safely builds a formatted string from the format string cformat and an arbitrary list of arguments.
The format string supports the conversion specifiers, length modifiers, and flags provided by printf() in the standard C++ library. The cformat string and {s} arguments must be UTF-8 encoded.
{lc} escape sequence expects a unicode character of type char16_t
, or ushort
(as returned by QChar::unicode()). The
{ls} escape sequence expects a pointer to a zero-terminated array of unicode characters of type char16_t
, or ushort (as returned by QString::utf16()). This is at odds with the printf() in the standard C++ library, which defines {lc}
to print a wchar_t and
{ls} to print a
{wchar_t*}, and might also produce compiler warnings on platforms where the size of {wchar_t}
is not 16 bits.For \l {QObject::tr()}{translations}, especially if the strings contains more than one escape sequence, you should consider using the arg() function instead. This allows the order of the replacements to be controlled by the translator.
Definition at line 6759 of file qstring.cpp.
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()).
Definition at line 1212 of file qstring.h.
|
inline |
Returns a reference to the last character in the string. Same as {operator[](size() - 1)}.
This function is provided for STL compatibility.
Definition at line 1330 of file qstring.h.
|
inline |
Returns the last character in the string. Same as {at(size() - 1)}.
This function is provided for STL compatibility.
Definition at line 444 of file qstring.h.
|
inline |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first character in the string.
! [iterator-invalidation-func-desc]
\sa constBegin(), end()
Definition at line 1331 of file qstring.h.
|
inline |
|
inline |
Returns the maximum number of characters that can be stored in the string without forcing a reallocation.
The sole purpose of this function is to provide a means of fine tuning QString's memory usage. In general, you will rarely ever need to call this function. If you want to know how many characters are in the string, call size().
Definition at line 1244 of file qstring.h.
|
inline |
|
inline |
Removes n characters from the end of the string.
If n is greater than or equal to size(), the result is an empty string; if n is negative, it is equivalent to passing zero.
Example:
If you want to remove characters from the beginning of the string, use remove() instead.
Definition at line 5955 of file qstring.cpp.
Returns a string that contains the size() - len leftmost characters of this string.
Definition at line 584 of file qstring.h.
|
inline |
|
noexcept |
Definition at line 6263 of file qstring.cpp.
|
inlinestaticnoexcept |
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().
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinenoexcept |
|
noexcept |
|
inlinestaticnoexcept |
|
inlinenoexcept |
|
inlinestaticnoexcept |
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the string.
iterator-invalidation-func-desc
Definition at line 1337 of file qstring.h.
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.
Definition at line 1234 of file qstring.h.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing just after the last character in the string.
iterator-invalidation-func-desc
Definition at line 1345 of file qstring.h.
|
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:
Definition at line 1348 of file qstring.h.
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
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.
Definition at line 4504 of file qstring.cpp.
qsizetype QString::count | ( | QChar | c, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) | const |
qsizetype QString::count | ( | QStringView | s, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) | const |
|
inline |
|
inline |
|
inline |
Returns a pointer to the data stored in the QString. The pointer can be used to access and modify the characters that compose the string.
Unlike constData() and unicode(), the returned data is always '\0'-terminated.
Example:
Note that the pointer remains valid only as long as the string is not modified by other means. For read-only access, constData() is faster because it never causes a \l{deep copy} to occur.
Definition at line 1228 of file qstring.h.
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 1220 of file qstring.h.
|
inline |
|
inline |
|
inline |
|
inline |
Returns an \l{STL-style iterators}{STL-style iterator} pointing just after the last character in the string.
iterator-invalidation-func-desc
Definition at line 1339 of file qstring.h.
|
inline |
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.
Definition at line 5143 of file qstring.cpp.
bool QString::endsWith | ( | QChar | c, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) | const |
Definition at line 5176 of file qstring.cpp.
bool QString::endsWith | ( | QLatin1String | s, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) | const |
Definition at line 5165 of file qstring.cpp.
|
inlinenoexcept |
QString::iterator QString::erase | ( | QString::const_iterator | first, |
QString::const_iterator | last | ||
) |
Removes from the string the characters in the half-open range [ first , last ). Returns an iterator to the character referred to by last before the erase.
Definition at line 8883 of file qstring.cpp.
Sets every character in the string to character ch. If size is different from -1 (default), the string is resized to size beforehand.
Example:
Definition at line 5973 of file qstring.cpp.
Returns a string that contains the first n characters of this string.
Definition at line 576 of file qstring.h.
Returns a QString initialized with the first size characters of the Latin-1 string str.
If size is {-1},
{strlen(str)} is used instead.
|
inlinestatic |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QString initialized with the Latin-1 string str.
Definition at line 767 of file qstring.h.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QString initialized with the Latin-1 string str.
Definition at line 5488 of file qstring.cpp.
Returns a QString initialized with the first size characters of the 8-bit string str.
If size is {-1},
{strlen(str)} is used instead.
On Unix systems this is equivalen to fromUtf8(), on Windows the systems current code page is being used.
|
inlinestatic |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QString initialized with the 8-bit string str.
Definition at line 789 of file qstring.h.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QString initialized with the 8-bit string str.
Definition at line 5563 of file qstring.cpp.
Constructs a QString that uses the first size Unicode characters in the array unicode. The data in unicode is not copied. The caller must be able to guarantee that unicode will not be deleted or modified as long as the QString (or an unmodified copy of it) exists.
Any attempts to modify the QString or copies of it will cause it to create a deep copy of the data, ensuring that the raw data isn't modified.
Here is an example of how we can use a QRegularExpression on raw data in memory without requiring to copy the data into a QString:
Definition at line 8938 of file qstring.cpp.
|
inlinestatic |
Returns a copy of the str string. The given string is converted to Unicode using the fromUtf8() function.
Definition at line 1452 of file qstring.h.
Returns a copy of the str string. The given string is assumed to be encoded in UTF-16.
Returns a copy of the str string. The given string is assumed to be encoded in UCS-4.
Returns a copy of the str string. The given string is assumed to be encoded in utf16 if the size of wchar_t is 2 bytes (e.g. on windows) and ucs4 if the size of wchar_t is 4 bytes (most Unix systems).
char32_t
overload instead. Returns a QString initialized with the first size characters of the Unicode string unicode (ISO-10646-UCS-4 encoded).
If size is -1 (default), unicode must be \0'-terminated.
Definition at line 5690 of file qstring.cpp.
If size is -1 (default), unicode must be \0'-terminated.
This function checks for a Byte Order Mark (BOM). If it is missing, host byte order is assumed.
This function is slow compared to the other Unicode conversions. Use QString(const QChar *, int) or QString(const QChar *) if possible.
QString makes a deep copy of the Unicode data.
char16_t
overload instead. Definition at line 5658 of file qstring.cpp.
Returns a QString initialized with the first size bytes of the UTF-8 string str.
If size is {-1},
{strlen(str)} is used instead.
UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QString. However, invalid sequences are possible with UTF-8 and, if any such are found, they will be replaced with one or more "replacement characters", or suppressed. These include non-Unicode sequences, non-characters, overlong sequences or surrogate codepoints encoded into UTF-8.
This function can be used to process incoming data incrementally as long as all UTF-8 characters are terminated within the incoming data. Any unterminated characters at the end of the string will be replaced or suppressed. In order to do stateful decoding, please use \l QStringDecoder.
|
inlinestatic |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QString initialized with the UTF-8 string str.
Definition at line 774 of file qstring.h.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QString initialized with the UTF-8 string str.
Definition at line 5632 of file qstring.cpp.
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.
|
inline |
Returns a reference to the first character in the string. Same as {operator[](0)}.
This function is provided for STL compatibility.
Definition at line 1329 of file qstring.h.
|
inline |
Returns the first character in the string. Same as {at(0)}.
This function is provided for STL compatibility.
Definition at line 442 of file qstring.h.
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.
Definition at line 4142 of file qstring.cpp.
qsizetype QString::indexOf | ( | QChar | c, |
qsizetype | from = 0 , |
||
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) | const |
Definition at line 4197 of file qstring.cpp.
qsizetype QString::indexOf | ( | QLatin1String | str, |
qsizetype | from = 0 , |
||
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) | const |
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.
Definition at line 4185 of file qstring.cpp.
|
inlinenoexcept |
|
inline |
QString & QString::insert | ( | qsizetype | i, |
QLatin1String | s | ||
) |
|
inline |
|
inline |
|
inline |
bool QString::isLower | ( | ) | const |
Returns true
if the string is lowercase, that is, it's identical to its toLower() folding.
Note that this does not mean that the string does not contain uppercase letters (some uppercase letters do not have a lowercase folding; they are left unchanged by toLower()). For more information, refer to the Unicode standard, section 3.13.
Definition at line 5220 of file qstring.cpp.
|
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.
Definition at line 1078 of file qstring.h.
bool QString::isRightToLeft | ( | ) | const |
Returns true
if the string is read right to left.
Definition at line 8780 of file qstring.cpp.
bool QString::isSimpleText | ( | ) | const |
Definition at line 8758 of file qstring.cpp.
bool QString::isUpper | ( | ) | const |
Returns true
if the string is uppercase, that is, it's identical to its toUpper() folding.
Note that this does not mean that the string does not contain lowercase letters (some lowercase letters do not have a uppercase folding; they are left unchanged by toUpper()). For more information, refer to the Unicode standard, section 3.13.
Definition at line 5194 of file qstring.cpp.
|
inlinenoexcept |
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.
Definition at line 1083 of file qstring.h.
Returns the string that contains the last n characters of this string.
Definition at line 578 of file qstring.h.
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:
{-1} is normally thought of as searching from the end of the string: the match at the end is after the last character, so it is excluded. To include such a final empty match, either give a positive value for from or omit the from parameter entirely.Definition at line 4226 of file qstring.cpp.
|
inline |
qsizetype QString::lastIndexOf | ( | QChar | c, |
qsizetype | from, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) | const |
Definition at line 4306 of file qstring.cpp.
|
inlinenoexcept |
qsizetype QString::lastIndexOf | ( | QLatin1String | s, |
qsizetype | from, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) | const |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
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.
Definition at line 4951 of file qstring.cpp.
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.
Definition at line 6518 of file qstring.cpp.
|
inline |
Definition at line 6403 of file qstring.cpp.
Compares s1 with s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.
The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.
|
inline |
|
inlinestatic |
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.
Definition at line 4994 of file qstring.cpp.
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.
Returns a string representing the floating-point number n.
Returns a string that represents n, formatted according to the specified format and precision.
For formats with an exponent, the exponent will show its sign and have at least two digits, left-padding the exponent with zero if needed.
Definition at line 7596 of file qstring.cpp.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 7538 of file qstring.cpp.
|
static |
Returns a string equivalent of the number n according to the specified base.
The base is 10 by default and must be between 2 and 36. For bases other than 10, n is treated as an unsigned integer.
The formatting always uses QLocale::C, i.e., English/UnitedStates. To get a localized string representation of a number, use QLocale::toString() with the appropriate locale.
Definition at line 7520 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 7554 of file qstring.cpp.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 7573 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 7546 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 7530 of file qstring.cpp.
|
inline |
|
inline |
|
inline |
Appends the string other onto the end of this string and returns a reference to this string.
Example:
This operation is typically very fast (\l{constant time}), because QString preallocates extra space at the end of the string data so it can grow without reallocating the entire string each time.
Definition at line 667 of file qstring.h.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Assigns other to this string and returns a reference to this string.
Definition at line 2822 of file qstring.cpp.
Definition at line 2886 of file qstring.cpp.
QString & QString::operator= | ( | QLatin1String | latin1 | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Prepends the string str to the beginning of this string and returns a reference to this string.
This operation is typically very fast (\l{constant time}), because QString preallocates extra space at the beginning of the string data, so it can grow without reallocating the entire string each time.
Example:
Definition at line 659 of file qstring.h.
|
inline |
|
inline |
|
inline |
|
inline |
QString & QString::remove | ( | const QString & | str, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) |
Removes every occurrence of the given str string in this string, and returns a reference to this string.
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
Definition at line 3310 of file qstring.cpp.
QString & QString::remove | ( | QChar | ch, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) |
Removes every occurrence of the character ch in this string, and returns a reference to this string.
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
Definition at line 3359 of file qstring.cpp.
QString & QString::remove | ( | QLatin1String | 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
Definition at line 3336 of file qstring.cpp.
Removes n characters from the string, starting at the given position index, and returns a reference to the string.
If the specified position index is within the string, but position + n is beyond the end of the string, the string is truncated at the specified position.
! [shrinking-erase] Element removal will preserve the string's capacity and not reduce the amount of allocated memory. To shed extra capacity and free as much memory as possible, call squeeze() after the last change to the string's size. ! [shrinking-erase]
Definition at line 3252 of file qstring.cpp.
|
inline |
|
inline |
|
inline |
Returns a copy of this string repeated the specified number of times.
If times is less than 1, an empty string is returned.
Example:
Definition at line 7818 of file qstring.cpp.
QString & QString::replace | ( | const QChar * | before, |
qsizetype | blen, | ||
const QChar * | after, | ||
qsizetype | alen, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) |
Definition at line 3573 of file qstring.cpp.
QString & QString::replace | ( | const QString & | before, |
const QString & | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) |
QString & QString::replace | ( | const QString & | before, |
QLatin1String | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) |
QString & QString::replace | ( | QChar | before, |
QChar | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) |
QString & QString::replace | ( | QChar | c, |
const QString & | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) |
QString & QString::replace | ( | QChar | c, |
QLatin1String | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) |
QString & QString::replace | ( | QLatin1String | before, |
const QString & | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) |
QString & QString::replace | ( | QLatin1String | before, |
QLatin1String | after, | ||
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) |
Replaces n characters beginning at index position with the string after and returns a reference to this string.
Example:
Definition at line 3419 of file qstring.cpp.
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.
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:
Definition at line 1307 of file qstring.h.
Sets the size of the string to size characters.
If size is greater than the current size, the string is extended to make it size characters long with the extra characters added to the end. The new characters are uninitialized.
If size is less than the current size, characters beyond position size are excluded from the string.
Example:
If you want to append a certain number of identical characters to the string, use the \l {QString::}{resize(qsizetype, QChar)} overload.
If you want to expand the string so that it reaches a certain width and fill the new positions with a particular character, use the leftJustified() function:
If size is negative, it is equivalent to passing zero.
Definition at line 2670 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Unlike \l {QString::}{resize(qsizetype)}, this overload initializes the new characters to fillChar:
Definition at line 2693 of file qstring.cpp.
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.
Definition at line 4970 of file qstring.cpp.
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.
Definition at line 6557 of file qstring.cpp.
|
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.
Definition at line 1272 of file qstring.h.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets the string to the printed value of n, formatted according to the given format and precision, and returns a reference to the string.
Definition at line 7480 of file qstring.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets the string to the printed value of n, formatted according to the given format and precision, and returns a reference to the string.
The formatting always uses QLocale::C, i.e., English/UnitedStates. To get a localized string representation of a number, use QLocale::toString() with the appropriate locale.
|
inline |
Sets the string to the printed value of n in the specified base, and returns a reference to the string.
The base is 10 by default and must be between 2 and 36.
The formatting always uses QLocale::C, i.e., English/UnitedStates. To get a localized string representation of a number, use QLocale::toString() with the appropriate locale.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 7448 of file qstring.cpp.
QString & QString::setNum | ( | qulonglong | n, |
int | base = 10 |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 7456 of file qstring.cpp.
|
inline |
Resets the QString to use the first size Unicode characters in the array unicode. The data in unicode is not copied. The caller must be able to guarantee that unicode will not be deleted or modified as long as the QString (or an unmodified copy of it) exists.
This function can be used instead of fromRawData() to re-use existings QString objects to save memory re-allocations.
Definition at line 8957 of file qstring.cpp.
Resizes the string to size characters and copies unicode into the string.
If unicode is \nullptr, nothing is copied, but the string is still resized to size.
Definition at line 5713 of file qstring.cpp.
Resizes the string to size characters and copies unicode into the string.
If unicode is \nullptr, nothing is copied, but the string is still resized to size.
Note that unlike fromUtf16(), this function does not consider BOMs and possibly differing byte ordering.
|
inline |
|
inline |
|
inline |
Returns a string that contains the portion of this string starting at position pos and extending to its end.
Definition at line 580 of file qstring.h.
Returns a string that contains n characters of this string, starting at position pos.
Definition at line 582 of file qstring.h.
QStringList QString::split | ( | const QRegularExpression & | sep, |
Qt::SplitBehavior | behavior = Qt::KeepEmptyParts |
||
) | const |
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:
Definition at line 7672 of file qstring.cpp.
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.
Definition at line 7681 of file qstring.cpp.
|
inline |
Releases any memory not required to store the character data.
The sole purpose of this function is to provide a means of fine tuning QString's memory usage. In general, you will rarely ever need to call this function.
Definition at line 1315 of file qstring.h.
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.
Definition at line 5092 of file qstring.cpp.
bool QString::startsWith | ( | QChar | c, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) | const |
Definition at line 5112 of file qstring.cpp.
bool QString::startsWith | ( | QLatin1String | s, |
Qt::CaseSensitivity | cs = Qt::CaseSensitive |
||
) | const |
Definition at line 5101 of file qstring.cpp.
|
inlinenoexcept |
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.
Definition at line 591 of file qstring.h.
double QString::toDouble | ( | bool * | ok = nullptr | ) | const |
Returns the string converted to a double
value.
Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).
If ok is not \nullptr, failure is reported by setting *{ok} to false
, and success by setting *{ok} to true
.
The string conversion will always happen in the 'C' locale. For locale-dependent conversion use QLocale::toDouble()
For historical reasons, this function does not handle thousands group separators. If you need to convert such numbers, use QLocale::toDouble().
This function ignores leading and trailing whitespace.
Definition at line 7374 of file qstring.cpp.
float QString::toFloat | ( | bool * | ok = nullptr | ) | const |
Returns the string converted to a float
value.
Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).
If ok is not \nullptr, failure is reported by setting *{ok} to false
, and success by setting *{ok} to true
.
The string conversion will always happen in the 'C' locale. For locale-dependent conversion use QLocale::toFloat()
For historical reasons, this function does not handle thousands group separators. If you need to convert such numbers, use QLocale::toFloat().
Example:
This function ignores leading and trailing whitespace.
Definition at line 7409 of file qstring.cpp.
QString QString::toHtmlEscaped | ( | ) | const |
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.
|
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.
Definition at line 848 of file qstring.h.
|
inline |
|
inline |
|
inline |
|
inline |
|
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.
Definition at line 852 of file qstring.h.
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.
Definition at line 7127 of file qstring.cpp.
|
inline |
|
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.
Definition at line 844 of file qstring.h.
|
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.
Definition at line 1449 of file qstring.h.
|
inline |
Returns a std::u16string object with the data contained in this QString. The Unicode data is the same as returned by the utf16() method.
Definition at line 1469 of file qstring.h.
|
inline |
Returns a std::u32string object with the data contained in this QString. The Unicode data is the same as returned by the toUcs4() method.
|
inline |
Returns a std::wstring object with the data contained in this QString. The std::wstring is encoded in 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.
Definition at line 1455 of file qstring.h.
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.
Definition at line 5440 of file qstring.cpp.
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.
Definition at line 850 of file qstring.h.
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.
Definition at line 854 of file qstring.h.
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.
Definition at line 7169 of file qstring.cpp.
|
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.
Definition at line 846 of file qstring.h.
|
inline |
|
inline |
|
inline |
Fills the array with the data contained in this QString object. The array is encoded in UTF-16 on platforms where wchar_t is 2 bytes wide (e.g. windows) and in 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.
|
inline |
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.
Definition at line 5934 of file qstring.cpp.
Returns a Unicode representation of the string. The result remains valid until the string is modified.
Definition at line 1218 of file qstring.h.
Returns the QString as a '\0\'-terminated array of unsigned shorts. The result remains valid until the string is modified.
The returned string is in host byte order.
Definition at line 6491 of file qstring.cpp.
Equivalent method to asprintf(), but takes a va_list ap instead a list of variable arguments. See the asprintf() documentation for an explanation of cformat.
This method does not call the va_end macro, the caller is responsible to call va_end on ap.
Definition at line 6853 of file qstring.cpp.
|
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)}
.
|
friend |
|
friend |
|
friend |
|
friend |
|
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.
{u} in those cases. It is optional otherwise.Literal operator that creates a QString out of the first size characters in the char16_t string literal str.
The QString is created at compile time, and the generated string data is stored in the read-only segment of the compiled object file. Duplicate literals may share the same read-only memory. This functionality is interchangeable with QStringLiteral, but saves typing when many string literals are present in the code.
The following code creates a QString:
Returns a string which is the result of concatenating s1 and s2 (s1 is converted to Unicode using the QString::fromUtf8() function).
Definition at line 1440 of file qstring.h.
Returns a string which is the result of concatenating s1 and s2 (s2 is converted to Unicode using the QString::fromUtf8() function).
Definition at line 1438 of file qstring.h.
|
friend |
|
friend |
|
related |
Writes the given string to the specified stream.
Definition at line 10084 of file qstring.cpp.
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
related |
Reads a string from the specified stream into the given string.
Definition at line 10116 of file qstring.cpp.
|
friend |
|
friend |
|
friend |