QStringView 類提供 UTF-16 字符串統一視圖,采用隻讀子集的 QString API. 更多...
| 頭: | #include <QStringView> |
| qmake: | QT += core |
| Since: | Qt 5.10 |
該類在 Qt 5.10 引入。
注意: 此類的所有函數 可重入 .
| typedef | const_iterator |
| typedef | const_pointer |
| typedef | const_reference |
| typedef | const_reverse_iterator |
| typedef | difference_type |
| typedef | iterator |
| typedef | pointer |
| typedef | reference |
| typedef | reverse_iterator |
| typedef | size_type |
| typedef | storage_type |
| typedef | value_type |
| QStringView (const StdBasicString & str ) | |
| QStringView (const QStringRef & str ) | |
| QStringView (const QString & str ) | |
| QStringView (const Char * str ) | |
| QStringView (const Char (&)[N] string = N) | |
| QStringView (const Char * first , const Char * last ) | |
| QStringView (const Char * str , qsizetype len ) | |
| QStringView ( std::nullptr_t ) | |
| QStringView () | |
| QString | arg (Args &&... args ) const |
| QChar | at (qsizetype n ) const |
| QChar | back () const |
| QStringView::const_iterator | begin () const |
| QStringView::const_iterator | cbegin () const |
| QStringView::const_iterator | cend () const |
| void | chop (qsizetype length ) |
| QStringView | chopped (qsizetype length ) const |
| int | compare (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | compare (QLatin1String l1 , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | compare (QChar ch ) const |
| int | compare (QChar ch , Qt::CaseSensitivity cs ) const |
| bool | contains (QChar c , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | contains (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | contains (QLatin1String l1 , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | count (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | count (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QStringView::const_reverse_iterator | crbegin () const |
| QStringView::const_reverse_iterator | crend () const |
| QStringView::const_pointer | data () const |
| bool | empty () const |
| QStringView::const_iterator | end () const |
| bool | endsWith (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | endsWith (QLatin1String l1 , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | endsWith (QChar ch ) const |
| bool | endsWith (QChar ch , Qt::CaseSensitivity cs ) const |
| QChar | first () const |
| QChar | front () const |
| qsizetype | indexOf (QChar c , qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | indexOf (QStringView str , qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | indexOf (QLatin1String l1 , qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | isEmpty () const |
| bool | isNull () const |
| bool | isRightToLeft () const |
| bool | isValidUtf16 () const |
| QChar | last () const |
| qsizetype | lastIndexOf (QChar c , qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | lastIndexOf (QStringView str , qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| qsizetype | lastIndexOf (QLatin1String l1 , qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QStringView | left (qsizetype length ) const |
| int | length () const |
| QStringView | mid (qsizetype start ) const |
| QStringView | mid (qsizetype start , qsizetype length ) const |
| QStringView::const_reverse_iterator | rbegin () const |
| QStringView::const_reverse_iterator | rend () const |
| QStringView | right (qsizetype length ) const |
| qsizetype | size () const |
| QList<QStringView> | split (QStringView sep , Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QList<QStringView> | split (QChar sep , Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QList<QStringView> | split (const QRegularExpression & sep , Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const |
| bool | startsWith (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | startsWith (QLatin1String l1 , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | startsWith (QChar ch ) const |
| bool | startsWith (QChar ch , Qt::CaseSensitivity cs ) const |
| double | toDouble (bool * ok = nullptr) const |
| float | toFloat (bool * ok = nullptr) const |
| int | toInt (bool * ok = nullptr, int base = 10) const |
| QByteArray | toLatin1 () const |
| QByteArray | toLocal8Bit () const |
| long | toLong (bool * ok = nullptr, int base = 10) const |
| qlonglong | toLongLong (bool * ok = nullptr, int base = 10) const |
| short | toShort (bool * ok = nullptr, int base = 10) const |
| QString | toString () const |
| uint | toUInt (bool * ok = nullptr, int base = 10) const |
| ulong | toULong (bool * ok = nullptr, int base = 10) const |
| qulonglong | toULongLong (bool * ok = nullptr, int base = 10) const |
| ushort | toUShort (bool * ok = nullptr, int base = 10) const |
| QVector<uint> | toUcs4 () const |
| QByteArray | toUtf8 () const |
| int | toWCharArray (wchar_t * array ) const |
| QStringView | trimmed () const |
| void | truncate (qsizetype length ) |
| const QStringView::storage_type * | utf16 () const |
| QChar | operator[] (qsizetype n ) const |
| uint | qHash (QStringView key , uint seed = 0) |
A QStringView references a contiguous portion of a UTF-16 string it does not own. It acts as an interface type to all kinds of UTF-16 string, without the need to construct a QString 首先。
The UTF-16 string may be represented as an array (or an array-compatible data-structure such as
QString
, std::basic_string, etc.) of
QChar
,
ushort
,
char16_t
or (on platforms, such as Windows, where it is a 16-bit type)
wchar_t
.
QStringView is designed as an interface type; its main use-case is as a function parameter type. When QStringViews are used as automatic variables or data members, care must be taken to ensure that the referenced string data (for example, owned by a QString ) outlives the QStringView on all code paths, lest the string view ends up referencing deleted data.
When used as an interface type, QStringView allows a single function to accept a wide variety of UTF-16 string data sources. One function accepting QStringView thus replaces three function overloads (taking
QString
,
QStringRef
,和
(const QChar*, int)
), while at the same time enabling even more string data sources to be passed to the function, such as
u"Hello World"
,
char16_t
字符串文字。
QStringViews should be passed by value, not by reference-to-const:
void myfun1(QStringView sv); // preferred
void myfun2(const QStringView &sv); // compiles and works, but slower
If you want to give your users maximum freedom in what strings they can pass to your function, accompany the QStringView overload with overloads for
void fun(QChar ch) { fun(QStringView(&ch, 1)); }
even though, for technical reasons, QStringView cannot provide a QChar constructor by itself.
QStringView can also be used as the return value of a function. If you call a function returning QStringView, take extra care to not keep the QStringView around longer than the function promises to keep the referenced string data alive. If in doubt, obtain a strong reference to the data by calling toString () to convert the QStringView into a QString .
QStringView is a
文字類型
, but since it stores data as
char16_t
, iteration is not
constexpr
(casts from
const char16_t*
to
const QChar*
, which is not allowed in
constexpr
functions). You can use an indexed loop and/or
utf16
() 在
constexpr
contexts instead.
注意: We strongly discourage the use of QList <QStringView>, because QList is a very inefficient container for QStringViews (it would heap-allocate every element). Use QVector (or std::vector) to hold QStringViews instead.
另請參閱 QString and QStringRef .
此 typedef 提供 STL 樣式 const 迭代器為 QStringView .
另請參閱 iterator and const_reverse_iterator .
彆名化的
value_type *
。為兼容 STL (標準模闆庫) 提供。
彆名化的
value_type &
。為兼容 STL (標準模闆庫) 提供。
This typedef provides an STL-style const reverse iterator for QStringView .
另請參閱 reverse_iterator and const_iterator .
彆名化的
std::ptrdiff_t
。為兼容 STL (標準模闆庫) 提供。
此 typedef 提供 STL 樣式 const 迭代器為 QStringView .
QStringView does not support mutable iterators, so this is the same as const_iterator .
另請參閱 const_iterator and reverse_iterator .
彆名化的
value_type *
。為兼容 STL (標準模闆庫) 提供。
QStringView does not support mutable pointers, so this is the same as const_pointer .
彆名化的
value_type &
。為兼容 STL (標準模闆庫) 提供。
QStringView does not support mutable references, so this is the same as const_reference .
This typedef provides an STL-style const reverse iterator for QStringView .
QStringView does not support mutable reverse iterators, so this is the same as const_reverse_iterator .
另請參閱 const_reverse_iterator and iterator .
彆名化的 qsizetype。為兼容 STL (標準模闆庫) 提供。
Unlike other Qt classes,
QStringView
uses qsizetype as its
size_type
, to allow accepting data from
std::basic_string
without truncation. The Qt API functions, for example
length
(), return
int
, while the STL-compatible functions, for example
size
(), return
size_type
.
彆名化的
char16_t
.
彆名化的
const QChar
。為兼容 STL (標準模闆庫) 提供。
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
見 QString::split () for how sep , behavior and cs interact to form the result.
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
Returns the index position of the last occurrence of the string-view str , Latin-1 string l1 , or character ch , respectively, in this string-view, searching backward from index position from 。若 from is -1 (default), the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if str 找不到。
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
該函數在 Qt 5.14 引入。
另請參閱 QString::lastIndexOf ().
返迴
true
if this string-view contains an occurrence of the string-view
str
, Latin-1 string
l1
, or character
ch
;否則返迴
false
.
若 cs is Qt::CaseSensitive (默認),搜索區分大小寫;否則,搜索不區分大小寫。
該函數在 Qt 5.14 引入。
另請參閱 indexOf ().
Returns the index position of the first occurrence of the string-view str , Latin-1 string l1 , or character ch , respectively, in this string-view, searching forward from index position from . Returns -1 if str 找不到。
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
若 from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.
該函數在 Qt 5.14 引入。
另請參閱 QString::indexOf ().
返迴
true
if this string-view ends with string-view
str
, Latin-1 string
l1
, or character
ch
, respectively; otherwise returns
false
.
若 cs is Qt::CaseSensitive (默認),搜索區分大小寫;否則,搜索不區分大小寫。
另請參閱 startsWith ().
返迴
true
if this string-view starts with string-view
str
, Latin-1 string
l1
, or character
ch
, respectively; otherwise returns
false
.
若 cs is Qt::CaseSensitive (默認),搜索區分大小寫;否則,搜索不區分大小寫。
另請參閱 endsWith ().
Returns an integer that compares to zero as this string-view compares to the Latin-1 string l1 , or character ch ,分彆。
若 cs is Qt::CaseSensitive (the default), the comparison is case sensitive; otherwise the comparison is case-insensitive.
該函數在 Qt 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
替換
%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 .
該函數在 Qt 5.14 引入。
另請參閱 QString::arg ().
構造字符串視圖對
str
。長度取自
str.size()
.
str.data()
必須在此字符串視圖對象的壽命內保持有效。
This constructor only participates in overload resolution if
StdBasicString
is an instantiation of
std::basic_string
with a compatible character type. The compatible character types are:
QChar
,
ushort
,
char16_t
and (on platforms, such as Windows, where it is a 16-bit type)
wchar_t
.
The string view will be empty if and only if
str.empty()
. It is unspecified whether this constructor can result in a null string view (
str.data()
would have to return
nullptr
for this).
構造字符串視圖對 str .
str.data()
必須在此字符串視圖對象的壽命內保持有效。
字符串視圖將為 null 當且僅當
str.isNull()
.
構造字符串視圖對 str .
str.data()
必須在此字符串視圖對象的壽命內保持有效。
字符串視圖將為 null 當且僅當
str.isNull()
.
構造字符串視圖對
str
. The length is determined by scanning for the first
Char(0)
.
str 必須在此字符串視圖對象的壽命內保持有效。
傳遞
nullptr
as
str
是安全的且結果在 null 字符串視圖中。
This constructor only participates in overload resolution if
str
is not an array and if
Char
is a compatible character type. The compatible character types are:
QChar
,
ushort
,
char16_t
and (on platforms, such as Windows, where it is a 16-bit type)
wchar_t
.
構造字符串視圖按字符串文字
string
. The length is set to
N-1
, excluding the trailing {Char(0)}. If you need the full array, use the constructor from pointer and size instead:
auto sv = QStringView(array, std::size(array)); // using C++17 std::size()
string 必須在此字符串視圖對象的壽命內保持有效。
This constructor only participates in overload resolution if
string
is an actual array and
Char
is a compatible character type. The compatible character types are:
QChar
,
ushort
,
char16_t
and (on platforms, such as Windows, where it is a 16-bit type)
wchar_t
.
構造字符串視圖對 first 按長度 ( last - first ).
範圍
[first,last)
必須在此字符串視圖對象的壽命內保持有效。
傳遞
\nullptr
as
first
是安全的若
last
is
nullptr
, too, and results in a null string view.
行為未定義若
last
precedes
first
,或
first
is
nullptr
and
last
is not.
This constructor only participates in overload resolution if
Char
is a compatible character type. The compatible character types are:
QChar
,
ushort
,
char16_t
and (on platforms, such as Windows, where it is a 16-bit type)
wchar_t
.
構造字符串視圖對 str 按長度 len .
範圍
[str,len)
必須在此字符串視圖對象的壽命內保持有效。
傳遞
nullptr
as
str
是安全的若
len
is 0, too, and results in a null string view.
行為未定義若
len
is negative or, when positive, if
str
is
nullptr
.
This constructor only participates in overload resolution if
Char
is a compatible character type. The compatible character types are:
QChar
,
ushort
,
char16_t
and (on platforms, such as Windows, where it is a 16-bit type)
wchar_t
.
構造 null 字符串視圖。
另請參閱 isNull ().
構造 null 字符串視圖。
另請參閱 isNull ().
返迴字符位於位置 n 在此字符串視圖。
行為未定義若 n is negative or not less than size ().
另請參閱 operator[] (), front (),和 back ().
返迴字符串中的最後一個字符。如同 last ().
此函數為兼容 STL (標準模闆庫) 提供。
警告: 在空字符串視圖調用此函數,將構成未定義行為。
另請參閱 front (), first (),和 last ().
返迴常量 STL 樣式迭代器 指嚮字符串中的首個字符。
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 end (), cbegin (), rbegin (),和 data ().
如同 begin ().
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 cend (), begin (), crbegin (),和 data ().
如同 end ().
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 cbegin (), end (),和 crend ().
截取此字符串視圖按 length 字符。
如同
*this = left(size() - length)
.
注意: 行為未定義當 length < 0 or length > size ().
另請參閱 mid (), left (), right (), chopped (),和 truncate ().
返迴子字符串長度 size () - length 起始於此對象的開頭。
如同
left(size() - length)
.
注意: 行為未定義當 length < 0 or length > size ().
另請參閱 mid (), left (), right (), chop (),和 truncate ().
Returns an integer that compares to zero as this string-view compares to the string-view str .
若 cs is Qt::CaseSensitive (the default), the comparison is case sensitive; otherwise the comparison is case-insensitive.
該函數在 Qt 5.12 引入。
Returns the number of occurrences of the character ch in the string reference.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
另請參閱 QString::count (), contains (),和 indexOf ().
這是重載函數。
Returns the number of (potentially overlapping) occurrences of the string reference str in this string reference.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
另請參閱 QString::count (), contains (),和 indexOf ().
如同 rbegin ().
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 crend (), rbegin (),和 cbegin ().
如同 rend ().
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 crbegin (), rend (),和 cend ().
Returns a const pointer to the first character in the string.
注意: The character array represented by the return value is not null-terminated.
另請參閱 begin (), end (),和 utf16 ().
Returns whether this string view is empty - that is, whether
size() == 0
.
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 isEmpty (), isNull (), size (),和 length ().
返迴常量 STL 樣式迭代器 pointing to the imaginary character after the last character in the list.
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 begin (), cend (),和 rend ().
Returns the first character in the string. Same as front ().
This function is provided for compatibility with other Qt containers.
警告: 在空字符串視圖調用此函數,將構成未定義行為。
另請參閱 front (), back (),和 last ().
Returns the first character in the string. Same as first ().
此函數為兼容 STL (標準模闆庫) 提供。
警告: 在空字符串視圖調用此函數,將構成未定義行為。
另請參閱 back (), first (),和 last ().
Returns whether this string view is empty - that is, whether
size() == 0
.
This function is provided for compatibility with other Qt containers.
另請參閱 empty (), isNull (), size (),和 length ().
Returns whether this string view is null - that is, whether
data() == nullptr
.
This functions is provided for compatibility with other Qt containers.
另請參閱 empty (), isEmpty (), size (),和 length ().
返迴
true
if the string is read right to left.
該函數在 Qt 5.11 引入。
另請參閱 QString::isRightToLeft ().
返迴
true
if the string contains valid UTF-16 encoded data, or
false
否則。
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.
該函數在 Qt 5.15 引入。
另請參閱 QString::isValidUtf16 ().
返迴字符串中的最後一個字符。如同 back ().
This function is provided for compatibility with other Qt containers.
警告: 在空字符串視圖調用此函數,將構成未定義行為。
另請參閱 back (), front (),和 first ().
返迴子字符串長度 length starting at position 0 in this object.
注意: Until 5.15.1, the behavior was undefined when length < 0 or length > size (). Since 5.15.2, the behavior is compatible with QString::left ().
另請參閱 mid (), right (), chopped (), chop (),和 truncate ().
如同
size
(), except returns the result as an
int
.
This function is provided for compatibility with other Qt containers.
警告:
QStringView
can represent strings with more than 2
31
characters. Calling this function on a string view for which
size
() returns a value greater than
INT_MAX
constitutes undefined behavior.
另請參閱 empty (), isEmpty (), isNull (),和 size ().
Returns the substring starting at position start in this object, and extending to the end of the string.
注意: Until 5.15.1, the behavior was undefined when start < 0 or start > size (). Since 5.15.2, the behavior is compatible with QString::mid ().
另請參閱 left (), right (), chopped (), chop (),和 truncate ().
這是重載函數。
返迴子字符串長度 length 起始於位置 start 在此對象。
注意: Until 5.15.1, the behavior was undefined when start < 0, length < 0, or start + length > size (). Since 5.15.2, the behavior is compatible with QString::mid ().
另請參閱 left (), right (), chopped (), chop (),和 truncate ().
返迴常量 STL-style reverse iterator pointing to the first character in the string, in reverse order.
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 rend (), crbegin (),和 begin ().
返迴 STL-style reverse iterator pointing to one past the last character in the string, in reverse order.
此函數為兼容 STL (標準模闆庫) 提供。
另請參閱 rbegin (), crend (),和 end ().
返迴子字符串長度 length 起始於位置 size () - length 在此對象。
注意: Until 5.15.1, the behavior was undefined when length < 0 or length > size (). Since 5.15.2, the behavior is compatible with QString::right ().
另請參閱 mid (), left (), chopped (), chop (),和 truncate ().
Returns the size of this string view, in UTF-16 code points (that is, surrogate pairs count as two for the purposes of this function, the same as in QString and QStringRef ).
另請參閱 empty (), isEmpty (), isNull (),和 length ().
Returns the string converted to a
double
值。
Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).
若
ok
不是
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 historic reasons, this function does not handle thousands group separators. If you need to convert such numbers, use QLocale::toDouble ().
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
另請參閱 QString::toDouble ().
Returns the string converted to a
float
值。
Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).
若
ok
不是
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 ()
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
另請參閱 QString::toFloat ().
Returns the string converted to an
int
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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::toInt ()
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
另請參閱 QString::toInt ().
Returns a Latin-1 representation of the string as a QByteArray .
The behavior is undefined if the string contains non-Latin1 characters.
另請參閱 toUtf8 (), toLocal8Bit (),和 QTextCodec .
Returns a local 8-bit representation of the string as a QByteArray .
QTextCodec::codecForLocale () is used to perform the conversion from Unicode. If the locale's encoding could not be determined, this function does the same as toLatin1 ().
The behavior is undefined if the string contains characters not supported by the locale's 8-bit encoding.
另請參閱 toLatin1 (), toUtf8 (),和 QTextCodec .
Returns the string converted to a
long
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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::toLong ()
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
另請參閱 QString::toLong ().
Returns the string converted to a
long long
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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::toLongLong ()
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
另請參閱 QString::toLongLong ().
Returns the string converted to a
short
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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::toShort ()
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
另請參閱 QString::toShort ().
Returns a deep copy of this string view's data as a QString .
The return value will be the null QString if and only if this string view is null.
警告:
QStringView
can store strings with more than 2
30
characters while
QString
cannot. Calling this function on a string view for which
size
() returns a value greater than
INT_MAX / 2
constitutes undefined behavior.
Returns the string converted to an
無符號 int
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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::toUInt ()
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
另請參閱 QString::toUInt ().
Returns the string converted to an
unsigned long
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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::toULongLong ()
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
另請參閱 QString::toULong ().
Returns the string converted to an
unsigned long long
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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::toULongLong ()
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
另請參閱 QString::toULongLong ().
Returns the string converted to an
unsigned short
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 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 ()
注意: This method has been added in 5.15.2 to simplify writing code that is portable between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5.
This function was introduced in Qt 5.15.2.
另請參閱 QString::toUShort ().
Returns a UCS-4/UTF-32 representation of the string as a QVector <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 replacement character (
QChar::ReplacementCharacter
, which corresponds to
U+FFFD
).
The returned vector is not 0-terminated.
另請參閱 toUtf8 (), toLatin1 (), toLocal8Bit (),和 QTextCodec .
Returns a UTF-8 representation of the string as a QByteArray .
UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QString .
另請參閱 toLatin1 (), toLocal8Bit (),和 QTextCodec .
Transcribes this string into the given array .
The caller is responsible for ensuring
array
is large enough to hold the
wchar_t
encoding of this string (allocating the array with the same length as the string is always sufficient). The array is encoded in UTF-16 on platforms where
wchar_t
is 2 bytes wide (e.g. Windows); otherwise (Unix systems),
wchar_t
is assumed to be 4 bytes wide and the data is written in UCS-4.
注意: This function writes no null terminator to the end of array .
Returns the number of
wchar_t
entries written to
array
.
該函數在 Qt 5.14 引入。
另請參閱 QString::toWCharArray ().
Strips leading and trailing whitespace and returns the result.
空白意味著任何字符其。
QChar::isSpace
() 返迴
true
。這包括 ASCII 字符 \t、\n、\v、\f、\r、及 " "。
Truncates this string view to length length .
如同
*this = left(length)
.
注意: 行為未定義當 length < 0 or length > size ().
另請參閱 mid (), left (), right (), chopped (),和 chop ().
Returns a const pointer to the first character in the string.
storage_type
is
char16_t
.
注意: The character array represented by the return value is not null-terminated.
另請參閱 begin (), end (),和 data ().
返迴字符位於位置 n 在此字符串視圖。
行為未定義若 n is negative or not less than size ().
另請參閱 at (), front (),和 back ().
返迴哈希值為 key ,使用 seed 做計算種子。
該函數在 Qt 5.10 引入。