QByteArrayView 類

QByteArrayView 類提供字節數組視圖,帶有隻讀子集的 QByteArray API. 更多...

頭: #include <QByteArrayView>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
Since: Qt 6.0

此類 強烈可比較 .

此類 強烈可比較 with QByteArray and const char *.

此類 強烈可比較 with QString , QStringView , QUtf8StringView , QLatin1StringView , QChar , and char16_t.

When comparing with string and Unicode character types, the content is interpreted as UTF-8.

注意: 此類的所有函數 可重入 .

公共類型

const_iterator
const_pointer
const_reference
const_reverse_iterator
difference_type
iterator
pointer
reference
reverse_iterator
size_type
storage_type
value_type

公共函數

QByteArrayView ()
QByteArrayView (const Byte * data )
QByteArrayView (const Container & c )
QByteArrayView (const QByteArray & byteArray )
QByteArrayView (const char (&)[Size] data )
QByteArrayView (std::nullptr_t)
QByteArrayView (const Byte * first , const Byte * last )
QByteArrayView (const Byte * data , qsizetype len )
char at (qsizetype n ) const
char back () const
QByteArrayView::const_iterator begin () const
QByteArrayView::const_iterator cbegin () const
QByteArrayView::const_iterator cend () const
void chop (qsizetype length )
QByteArrayView chopped (qsizetype length ) const
(從 6.2 起) int compare (QByteArrayView bv , Qt::CaseSensitivity cs = Qt::CaseSensitive) const
QByteArrayView::const_pointer constData () const
bool contains (QByteArrayView bv ) const
bool contains (char ch ) const
qsizetype count (QByteArrayView bv ) const
qsizetype count (char ch ) const
QByteArrayView::const_reverse_iterator crbegin () const
QByteArrayView::const_reverse_iterator crend () const
QByteArrayView::const_pointer data () const
bool empty () const
QByteArrayView::const_iterator end () const
bool endsWith (QByteArrayView bv ) const
bool endsWith (char ch ) const
QByteArrayView first (qsizetype n ) const
char front () const
qsizetype indexOf (QByteArrayView bv , qsizetype from = 0) const
qsizetype indexOf (char ch , qsizetype from = 0) const
bool isEmpty () const
bool isNull () const
(從 6.3 起) bool isValidUtf8 () const
QByteArrayView last (qsizetype n ) const
qsizetype lastIndexOf (QByteArrayView bv , qsizetype from ) const
qsizetype lastIndexOf (char ch , qsizetype from = -1) const
(從 6.2 起) qsizetype lastIndexOf (QByteArrayView bv ) const
qsizetype length () const
(從 6.8 起) qsizetype max_size () const
QByteArrayView::const_reverse_iterator rbegin () const
QByteArrayView::const_reverse_iterator rend () const
qsizetype size () const
(從 6.8 起) QByteArrayView & slice (qsizetype pos , qsizetype n )
(從 6.8 起) QByteArrayView & slice (qsizetype pos )
QByteArrayView sliced (qsizetype pos ) const
QByteArrayView sliced (qsizetype pos , qsizetype n ) const
bool startsWith (QByteArrayView bv ) const
bool startsWith (char ch ) const
QByteArray toByteArray () const
(從 6.3 起) double toDouble (bool * ok = nullptr) const
(從 6.3 起) float toFloat (bool * ok = nullptr) const
(從 6.3 起) int toInt (bool * ok = nullptr, int base = 10) const
(從 6.3 起) long toLong (bool * ok = nullptr, int base = 10) const
(從 6.3 起) qlonglong toLongLong (bool * ok = nullptr, int base = 10) const
(從 6.3 起) short toShort (bool * ok = nullptr, int base = 10) const
(從 6.3 起) uint toUInt (bool * ok = nullptr, int base = 10) const
(從 6.3 起) ulong toULong (bool * ok = nullptr, int base = 10) const
(從 6.3 起) qulonglong toULongLong (bool * ok = nullptr, int base = 10) const
(從 6.3 起) ushort toUShort (bool * ok = nullptr, int base = 10) const
(從 6.3 起) QByteArrayView trimmed () const
void truncate (qsizetype length )
(從 6.7 起) std::string_view operator std::string_view () const
char operator[] (qsizetype n ) const

靜態公共成員

QByteArrayView fromArray (const Byte (&)[Size] data )
(從 6.8 起) qsizetype maxSize ()
bool operator!= (const QByteArrayView & lhs , const QByteArrayView & rhs )
bool operator< (const QByteArrayView & lhs , const QByteArrayView & rhs )
bool operator<= (const QByteArrayView & lhs , const QByteArrayView & rhs )
bool operator== (const QByteArrayView & lhs , const QByteArrayView & rhs )
bool operator> (const QByteArrayView & lhs , const QByteArrayView & rhs )
bool operator>= (const QByteArrayView & lhs , const QByteArrayView & rhs )

詳細描述

A QByteArrayView references a contiguous portion of raw bytes it does not own. It acts as an interface type to all kinds of byte-array-like data, without the need to construct a QByteArray 首先。

The byte array data may be represented as an array (or an array-compatible data-structure such as QByteArray , std::basic_string, etc.) of char , signed char , unsigned char or std::byte .

QByteArrayView is designed as an interface type; its main use-case is as a function parameter type. When QByteArrayViews are used as automatic variables or data members, care must be taken to ensure that the referenced data (for example, owned by a QByteArray ) outlives the QByteArrayView on all code paths, lest the byte array view ends up referencing deleted data.

When used as an interface type, QByteArrayView allows a single function to accept a wide variety of byte-array-like data sources. One function accepting QByteArrayView thus replaces several function overloads (taking, for example, QByteArray , const char *, etc.) while at the same time enabling even more byte array data sources to be passed to the function.

QByteArrayView should be passed by value, not by reference-to-const:

    void myfun1(QByteArrayView bv);        // preferred
    void myfun2(const QByteArrayView &bv); // compiles and works, but slower
					

If you want to give your users maximum freedom in what type of data they can pass to your function, accompany the QByteArrayView overload with overloads for

  • char : this overload can delegate to the QByteArrayView version:
        void fun(QByteArrayView bv);
        void fun(char ch) { fun(QByteArrayView(&ch, 1)); }
    							

    even though, for technical reasons, QByteArrayView cannot provide a char constructor by itself.

  • QByteArray : if you store an unmodified copy of the byte array and thus would like to take advantage of QByteArray 's implicit sharing.

QByteArrayView can also be used as the return value of a function. If you call a function returning QByteArrayView, take extra care to not keep the QByteArrayView around longer than the function promises to keep the referenced data alive. If in doubt, obtain a strong reference to the data by calling toByteArray () to convert the QByteArrayView into a QByteArray .

The methods supported by QByteArrayView reflect those of QByteArray . In particular, to the limited degree that it ascribes semantics (such as character case, spacing, digits of numbers) to the character data viewed, it uses the C locale and ASCII encoding. See C 區域設置和 ASCII 函數 for details and the limitations on these methods.

兼容字節類型

QByteArrayView can be constructed on any container of bytes, where the byte type is one of:

  • char (有符號和無符號兩者)
  • std::byte

另請參閱 QByteArray and QStringView .

成員類型文檔編製

QByteArrayView:: const_iterator

此 typedef 提供 STL 樣式 const 迭代器為 QByteArrayView .

另請參閱 iterator and const_reverse_iterator .

QByteArrayView:: const_pointer

彆名化的 value_type * 。為兼容 STL (標準模闆庫) 提供。

QByteArrayView:: const_reference

彆名化的 value_type & 。為兼容 STL (標準模闆庫) 提供。

QByteArrayView:: const_reverse_iterator

This typedef provides an STL-style const reverse iterator for QByteArrayView .

另請參閱 reverse_iterator and const_iterator .

QByteArrayView:: difference_type

彆名化的 std::ptrdiff_t 。為兼容 STL (標準模闆庫) 提供。

QByteArrayView:: iterator

此 typedef 提供 STL 樣式 const 迭代器為 QByteArrayView .

QByteArrayView does not support mutable iterators, so this is the same as const_iterator .

另請參閱 const_iterator and reverse_iterator .

QByteArrayView:: pointer

彆名化的 value_type * 。為兼容 STL (標準模闆庫) 提供。

QByteArrayView does not support mutable pointers, so this is the same as const_pointer .

QByteArrayView:: reference

彆名化的 value_type & 。為兼容 STL (標準模闆庫) 提供。

QByteArrayView does not support mutable references, so this is the same as const_reference .

QByteArrayView:: reverse_iterator

This typedef provides an STL-style const reverse iterator for QByteArrayView .

QByteArrayView does not support mutable reverse iterators, so this is the same as const_reverse_iterator .

另請參閱 const_reverse_iterator and iterator .

QByteArrayView:: size_type

彆名化的 qsizetype。為兼容 STL (標準模闆庫) 提供。

QByteArrayView:: storage_type

彆名化的 char .

QByteArrayView:: value_type

彆名化的 const char 。為兼容 STL (標準模闆庫) 提供。

成員函數文檔編製

[noexcept] bool QByteArrayView:: startsWith ( QByteArrayView bv ) const

[constexpr noexcept] bool QByteArrayView:: startsWith ( char ch ) const

返迴 true if this byte array view starts with byte array view bv or character ch , respectively; otherwise returns false .

另請參閱 endsWith ().

[noexcept] bool QByteArrayView:: endsWith ( QByteArrayView bv ) const

[constexpr noexcept] bool QByteArrayView:: endsWith ( char ch ) const

返迴 true if this byte array view ends with byte array view bv or character ch , respectively; otherwise returns false .

另請參閱 startsWith ().

[noexcept] qsizetype QByteArrayView:: indexOf ( QByteArrayView bv , qsizetype from = 0) const

[noexcept] qsizetype QByteArrayView:: indexOf ( char ch , qsizetype from = 0) const

Returns the index position of either the start of the first occurrence of the sequence of bytes viewed by bv or the first occurrence of byte ch , respectively, in this byte array view, searching forward from index position from.Returns -1 if no match is found.

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

另請參閱 lastIndexOf () 和 contains ().

[noexcept] bool QByteArrayView:: contains ( QByteArrayView bv ) const

[noexcept] bool QByteArrayView:: contains ( char ch ) const

返迴 true if this byte array view contains an occurrence of the sequence of bytes viewed by bv or character ch , respectively; otherwise returns false .

另請參閱 indexOf () 和 lastIndexOf ().

[noexcept] qsizetype QByteArrayView:: lastIndexOf ( QByteArrayView bv , qsizetype from ) const

[noexcept] qsizetype QByteArrayView:: lastIndexOf ( char ch , qsizetype from = -1) const

Returns the index position of either the start of the last occurrence of the sequence of bytes viewed by bv or the last occurrence of byte ch , respectively, in this byte array view, searching backward from index position from .

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

Returns -1 if no match is found.

注意: When searching for a 0-length bv , the match at the end of the data is excluded from the search by a negative from , even though -1 is normally thought of as searching from the end of the view: 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.

另請參閱 indexOf () 和 contains ().

[constexpr noexcept] QByteArrayView:: QByteArrayView ()

Constructs a null byte array view.

另請參閱 isNull ().

[constexpr noexcept] template <typename Byte> QByteArrayView:: QByteArrayView (const Byte * data )

Constructs a byte array view on data . The length is determined by scanning for the first Byte(0) .

data must remain valid for the lifetime of this byte array view object.

傳遞 nullptr as data is safe and results in a null byte array view.

This constructor only participates in overload resolution if data is not an array and if Byte is a compatible byte type.

另請參閱 兼容字節類型 .

[constexpr noexcept] template <typename Container, QByteArrayView::if_compatible_container<Container> = true> QByteArrayView:: QByteArrayView (const 容器 & c )

Constructs a byte array view on the array-like container c . The length and data are set via std::size(c) and std::data(c) 分彆。

The container's data must remain valid for the lifetime of this byte array view object.

This constructor participates in overload resolution if c is any contiguous container with elements of a compatible byte type.

另請參閱 兼容字節類型 .

[noexcept] QByteArrayView:: QByteArrayView (const QByteArray & byteArray )

Constructs a byte array view on byteArray .

byteArray.data() must remain valid for the lifetime of this byte array view object.

The byte array view will be null if and only if byteArray.isNull() .

[constexpr noexcept] template <size_t Size> QByteArrayView:: QByteArrayView (const char (&)[ Size ] data )

Constructs a byte array view on the char array data 。視圖覆蓋數組,直到第 1 個 '\0' 被遇到,或 Size ,以先到的為準。若需要完整數組,使用 fromArray () 代替。

data must remain valid for the lifetime of this byte array view object.

注意: This constructor is only available for char array literals. The reasoning behind that is for compatibility with C-libraries which predefine "large-enough" arrays, but only use some of the preallocated space. To support this in an intuitive way in an implicit constructor overload, we need to stop at the first char(0) . This is logical for a char array, but not for a std::byte 數組。

另請參閱 fromArray .

[constexpr noexcept] QByteArrayView:: QByteArrayView ( std::nullptr_t )

Constructs a null byte array view.

另請參閱 isNull ().

[constexpr] template <typename Byte, QByteArrayView::if_compatible_byte<Byte> = true> QByteArrayView:: QByteArrayView (const Byte * first , const Byte * last )

Constructs a byte array view on first 按長度 ( last - first ).

範圍 [first,last) must remain valid for the lifetime of this QByteArrayView.

傳遞 \nullptr as first 是安全的若 last is nullptr , too, and results in a null byte array view.

行為未定義若 last precedes first ,或 first is nullptr and last is not.

This constructor only participates in overload resolution if Byte is a compatible byte type.

另請參閱 兼容字節類型 .

[constexpr] template <typename Byte, QByteArrayView::if_compatible_byte<Byte> = true> QByteArrayView:: QByteArrayView (const Byte * data , qsizetype len )

Constructs a byte array view on data 按長度 len .

範圍 [data,len) must remain valid for the lifetime of this QByteArrayView.

傳遞 nullptr as data 是安全的若 len is 0, too, and results in a null byte array view.

行為未定義若 len is negative or, when positive, if data is nullptr .

This constructor only participates in overload resolution if Byte is a compatible byte type.

另請參閱 兼容字節類型 .

[constexpr] char QByteArrayView:: at ( qsizetype n ) const

返迴字符位於位置 n in this byte array view.

行為未定義若 n is negative or not less than size ().

另請參閱 operator[] (), front (),和 back ().

[constexpr] char QByteArrayView:: back () const

Returns the last byte in the byte array view.

此函數為兼容 STL (標準模闆庫) 提供。

警告: Calling this function on an empty byte array view constitutes undefined behavior.

另請參閱 front ().

[constexpr noexcept] QByteArrayView::const_iterator QByteArrayView:: begin () const

返迴常量 STL 樣式迭代器 pointing to the first byte in the byte array view.

此函數為兼容 STL (標準模闆庫) 提供。

另請參閱 end (), cbegin (), rbegin (),和 data ().

[constexpr noexcept] QByteArrayView::const_iterator QByteArrayView:: cbegin () const

如同 begin ().

此函數為兼容 STL (標準模闆庫) 提供。

另請參閱 cend (), begin (), crbegin (),和 data ().

[constexpr noexcept] QByteArrayView::const_iterator QByteArrayView:: cend () const

如同 end ().

此函數為兼容 STL (標準模闆庫) 提供。

另請參閱 cbegin (), end (),和 crend ().

[constexpr] void QByteArrayView:: chop ( qsizetype length )

Truncates this byte array view by length 字符。

如同 *this = first(size() - length) .

注意: 行為未定義當 length < 0 or length > size ().

另請參閱 sliced (), first (), last (), chopped (), truncate (),和 slice ().

[constexpr] QByteArrayView QByteArrayView:: chopped ( qsizetype length ) const

Returns a copy of this byte array view that omits its last length bytes. In other words, returns a byte array view of length size () - length 起始於此對象的開頭。

如同 first(size() - length) .

注意: 行為未定義當 length < 0 or length > size ().

另請參閱 first (), last (), sliced (), chop (), truncate (),和 slice ().

[noexcept, since 6.2] int QByteArrayView:: compare ( QByteArrayView bv , Qt::CaseSensitivity cs = Qt::CaseSensitive) const

Returns an integer less than, equal to, or greater than zero depending on whether this QByteArrayView sorts before, at the same position as, or after the QByteArrayView bv . The comparison is performed according to case sensitivity cs .

該函數在 Qt 6.2 引入。

另請參閱 operator== ().

[constexpr noexcept] QByteArrayView::const_pointer QByteArrayView:: constData () const

返迴常量 char pointer to the first byte in the byte array view.

注意: The character array represented by the return value is not guaranteed to be null-terminated. The returned pointer is only safe to use for accessing bytes at indices that are less than this byte array view's size ().

另請參閱 data (), begin (),和 end ().

[noexcept] qsizetype QByteArrayView:: count ( QByteArrayView bv ) const

Returns the number of (potentially overlapping) occurrences of the sequence of bytes viewed by bv in this byte array view.

另請參閱 contains () 和 indexOf ().

[noexcept] qsizetype QByteArrayView:: count ( char ch ) const

這是重載函數。

Returns the number of occurrences of byte ch in this byte array view.

另請參閱 contains () 和 indexOf ().

[constexpr noexcept] QByteArrayView::const_reverse_iterator QByteArrayView:: crbegin () const

如同 rbegin ().

此函數為兼容 STL (標準模闆庫) 提供。

另請參閱 crend (), rbegin (),和 cbegin ().

[constexpr noexcept] QByteArrayView::const_reverse_iterator QByteArrayView:: crend () const

如同 rend ().

此函數為兼容 STL (標準模闆庫) 提供。

另請參閱 crbegin (), rend (),和 cend ().

[constexpr noexcept] QByteArrayView::const_pointer QByteArrayView:: data () const

返迴常量 char pointer to the first byte in the byte array view.

注意: The character array represented by the return value is not guaranteed to be null-terminated. The returned pointer is only safe to use for accessing bytes at indices that are less than this byte array view's size ().

另請參閱 begin () 和 end ().

[constexpr noexcept] bool QByteArrayView:: empty () const

返迴 true if this byte array view is empty - that is, size() == 0 .

此函數為兼容 STL (標準模闆庫) 提供。

另請參閱 isEmpty (), isNull (),和 size ().

[constexpr noexcept] QByteArrayView::const_iterator QByteArrayView:: end () const

返迴常量 STL 樣式迭代器 pointing just after the last byte in the byte array view.

此函數為兼容 STL (標準模闆庫) 提供。

另請參閱 begin (), cend (),和 rend ().

[constexpr] QByteArrayView QByteArrayView:: first ( qsizetype n ) const

Returns a byte array view that points to the first n bytes of this byte array view. Equivalent to sliced(0, n) .

注意: 行為未定義當 n < 0 or n > size ().

另請參閱 last (), startsWith (), chopped (), chop (), truncate (), sliced (),和 slice ().

[static constexpr noexcept] template <typename Byte, size_t Size> QByteArrayView QByteArrayView:: fromArray (const Byte (&)[ Size ] data )

Constructs a byte array view on the array literal data . The view covers the full array. That includes the trailing null-terminator of char array literals. If you don't want the null-terminator included in the view, you can chop () it off when you are certain it is at the end. Alternatively you can use the constructor overload taking a char array literal which will create a view up to, but not including, the first null-terminator in the data.

This function will work with any array literal of a compatible byte type.

另請參閱 兼容字節類型 and QByteArrayView .

[constexpr] char QByteArrayView:: front () const

Returns the first byte in the byte array view.

此函數為兼容 STL (標準模闆庫) 提供。

警告: Calling this function on an empty byte array view constitutes undefined behavior.

另請參閱 back ().

[constexpr noexcept] bool QByteArrayView:: isEmpty () const

返迴 true if this byte array view is empty - that is, size() == 0 .

另請參閱 empty (), isNull (),和 size ().

[constexpr noexcept] bool QByteArrayView:: isNull () const

返迴 true if this byte array view is null - that is, data() == nullptr .

另請參閱 empty (), isEmpty (),和 size ().

[noexcept, since 6.3] bool QByteArrayView:: isValidUtf8 () const

返迴 true if this byte array view contains valid UTF-8 encoded data, or false 否則。

該函數在 Qt 6.3 引入。

[constexpr] QByteArrayView QByteArrayView:: last ( qsizetype n ) const

Returns a byte array view that points to the last n bytes of this byte array view.

注意: 行為未定義當 n < 0 or n > size ().

另請參閱 first (), endsWith (), chopped (), chop (), truncate (), sliced (),和 slice ().

[noexcept, since 6.2] qsizetype QByteArrayView:: lastIndexOf ( QByteArrayView bv ) const

這是重載函數。

Returns the index position of the start of the last occurrence of the sequence of bytes viewed by bv in this byte array view, searching backward from the end of this byte array view. Returns -1 if no match is found.

該函數在 Qt 6.2 引入。

另請參閱 indexOf () 和 contains ().

[constexpr noexcept] qsizetype QByteArrayView:: length () const

如同 size ().

另請參閱 empty (), isEmpty (), isNull (),和 size ().

[static constexpr noexcept, since 6.8] qsizetype QByteArrayView:: maxSize ()

It returns the maximum number of elements that the view can theoretically represent. In practice, the number can be much smaller, limited by the amount of memory available to the system.

該函數在 Qt 6.8 引入。

[constexpr noexcept, since 6.8] qsizetype QByteArrayView:: max_size () const

此函數為兼容 STL (標準模闆庫) 提供。

返迴 maxSize ().

該函數在 Qt 6.8 引入。

[constexpr noexcept] QByteArrayView::const_reverse_iterator QByteArrayView:: rbegin () const

返迴常量 STL-style reverse iterator pointing to the first byte in the byte array view, in reverse order.

此函數為兼容 STL (標準模闆庫) 提供。

另請參閱 rend (), crbegin (),和 begin ().

[constexpr noexcept] QByteArrayView::const_reverse_iterator QByteArrayView:: rend () const

返迴 STL-style reverse iterator pointing to one past the last byte in the byte array view, in reverse order.

此函數為兼容 STL (標準模闆庫) 提供。

另請參閱 rbegin (), crend (),和 end ().

[constexpr noexcept] qsizetype QByteArrayView:: size () const

Returns the number of bytes in this byte array view.

另請參閱 empty (), isEmpty (),和 isNull ().

[constexpr, since 6.8] QByteArrayView &QByteArrayView:: slice ( qsizetype pos , qsizetype n )

Modifies this byte array view to start at position pos , extending for n 字節。

注意: 行為未定義當 pos < 0, n < 0, or pos + n > size ().

該函數在 Qt 6.8 引入。

另請參閱 sliced (), first (), last (), chopped (), chop (),和 truncate ().

[constexpr, since 6.8] QByteArrayView &QByteArrayView:: slice ( qsizetype pos )

這是重載函數。

Modifies this byte array view to start at position pos , extending to its end.

注意: 行為未定義當 pos < 0 or pos > size ().

該函數在 Qt 6.8 引入。

另請參閱 sliced (), first (), last (), chopped (), chop (),和 truncate ().

[constexpr] QByteArrayView QByteArrayView:: sliced ( qsizetype pos ) const

Returns a byte array view starting at position pos in this object, and extending to its end.

注意: 行為未定義當 pos < 0 or pos > size ().

另請參閱 first (), last (), chopped (), chop (), truncate (),和 slice ().

[constexpr] QByteArrayView QByteArrayView:: sliced ( qsizetype pos , qsizetype n ) const

Returns a byte array view that points to n bytes of this byte array view, starting at position pos .

注意: 行為未定義當 pos < 0, n < 0, or pos + n > size ().

另請參閱 first (), last (), chopped (), chop (), truncate (),和 slice ().

QByteArray QByteArrayView:: toByteArray () const

Returns a deep copy of this byte array view's data as a QByteArray .

The return value will be a null QByteArray if and only if this byte array view is null.

[since 6.3] double QByteArrayView:: toDouble ( bool * ok = nullptr) const

Returns this byte array view 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 QByteArrayView content may only contain valid numerical characters which includes the plus/minus sign, the character e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.

注意: The conversion of the number is performed in the default C locale, regardless of the user's locale. Use QLocale to perform locale-aware conversions between numbers and strings.

This function ignores leading and trailing spacing characters.

該函數在 Qt 6.3 引入。

[since 6.3] float QByteArrayView:: toFloat ( bool * ok = nullptr) const

Returns this byte array view 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 .

QByteArrayView string("1234.56 Volt");
bool ok;
float a = str.toFloat(&ok);       // a == 0, ok == false
a = string.first(7).toFloat(&ok); // a == 1234.56, ok == true
					

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

注意: The conversion of the number is performed in the default C locale, regardless of the user's locale. Use QLocale to perform locale-aware conversions between numbers and strings.

此函數忽略前導和結尾空格。

該函數在 Qt 6.3 引入。

[since 6.3] int QByteArrayView:: toInt ( bool * ok = nullptr, int base = 10) const

Returns this byte array view converted to an int 使用基 base , which is ten by default. Bases 0 and 2 through 36 are supported, using letters for digits beyond 9; A is ten, B is eleven and so on.

base is 0, the base is determined automatically using the following rules: if the byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is read as octal (base 8); otherwise it is read as decimal.

返迴 0,若轉換失敗。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

QByteArrayView str("FF");
bool ok;
int hex = str.toInt(&ok, 16);     // hex == 255, ok == true
int dec = str.toInt(&ok, 10);     // dec == 0, ok == false
					

注意: The conversion of the number is performed in the default C locale, regardless of the user's locale. Use QLocale to perform locale-aware conversions between numbers and strings.

該函數在 Qt 6.3 引入。

[since 6.3] long QByteArrayView:: toLong ( bool * ok = nullptr, int base = 10) const

Returns this byte array view converted to a long int using base base , which is ten by default. Bases 0 and 2 through 36 are supported, using letters for digits beyond 9; A is ten, B is eleven and so on.

base is 0, the base is determined automatically using the following rules: if the byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is read as octal (base 8); otherwise it is read as decimal.

返迴 0,若轉換失敗。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

QByteArrayView str("FF");
bool ok;
long hex = str.toLong(&ok, 16);   // hex == 255, ok == true
long dec = str.toLong(&ok, 10);   // dec == 0, ok == false
					

注意: The conversion of the number is performed in the default C locale, regardless of the user's locale. Use QLocale to perform locale-aware conversions between numbers and strings.

該函數在 Qt 6.3 引入。

[since 6.3] qlonglong QByteArrayView:: toLongLong ( bool * ok = nullptr, int base = 10) const

Returns this byte array view converted to a long long 使用基 base , which is ten by default. Bases 0 and 2 through 36 are supported, using letters for digits beyond 9; A is ten, B is eleven and so on.

base is 0, the base is determined automatically using the following rules: if the byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is read as octal (base 8); otherwise it is read as decimal.

返迴 0,若轉換失敗。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

注意: The conversion of the number is performed in the default C locale, regardless of the user's locale. Use QLocale to perform locale-aware conversions between numbers and strings.

該函數在 Qt 6.3 引入。

[since 6.3] short QByteArrayView:: toShort ( bool * ok = nullptr, int base = 10) const

Returns this byte array view converted to a short 使用基 base , which is ten by default. Bases 0 and 2 through 36 are supported, using letters for digits beyond 9; A is ten, B is eleven and so on.

base is 0, the base is determined automatically using the following rules: if the byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is read as octal (base 8); otherwise it is read as decimal.

返迴 0,若轉換失敗。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

注意: The conversion of the number is performed in the default C locale, regardless of the user's locale. Use QLocale to perform locale-aware conversions between numbers and strings.

該函數在 Qt 6.3 引入。

[since 6.3] uint QByteArrayView:: toUInt ( bool * ok = nullptr, int base = 10) const

Returns this byte array view converted to an unsigned int 使用基 base , which is ten by default. Bases 0 and 2 through 36 are supported, using letters for digits beyond 9; A is ten, B is eleven and so on.

base is 0, the base is determined automatically using the following rules: if the byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is read as octal (base 8); otherwise it is read as decimal.

返迴 0,若轉換失敗。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

注意: The conversion of the number is performed in the default C locale, regardless of the user's locale. Use QLocale to perform locale-aware conversions between numbers and strings.

該函數在 Qt 6.3 引入。

[since 6.3] ulong QByteArrayView:: toULong ( bool * ok = nullptr, int base = 10) const

Returns this byte array view converted to an unsigned long int 使用基 base , which is ten by default. Bases 0 and 2 through 36 are supported, using letters for digits beyond 9; A is ten, B is eleven and so on.

base is 0, the base is determined automatically using the following rules: if the byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is read as octal (base 8); otherwise it is read as decimal.

返迴 0,若轉換失敗。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

注意: The conversion of the number is performed in the default C locale, regardless of the user's locale. Use QLocale to perform locale-aware conversions between numbers and strings.

該函數在 Qt 6.3 引入。

[since 6.3] qulonglong QByteArrayView:: toULongLong ( bool * ok = nullptr, int base = 10) const

Returns this byte array view converted to an unsigned long long 使用基 base , which is ten by default. Bases 0 and 2 through 36 are supported, using letters for digits beyond 9; A is ten, B is eleven and so on.

base is 0, the base is determined automatically using the following rules: if the byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is read as octal (base 8); otherwise it is read as decimal.

返迴 0,若轉換失敗。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

注意: The conversion of the number is performed in the default C locale, regardless of the user's locale. Use QLocale to perform locale-aware conversions between numbers and strings.

該函數在 Qt 6.3 引入。

[since 6.3] ushort QByteArrayView:: toUShort ( bool * ok = nullptr, int base = 10) const

Returns this byte array view converted to an unsigned short 使用基 base , which is ten by default. Bases 0 and 2 through 36 are supported, using letters for digits beyond 9; A is ten, B is eleven and so on.

base is 0, the base is determined automatically using the following rules: if the byte array view begins with "0x", the rest of it is read as hexadecimal (base 16); otherwise, if it begins with "0", the rest of it is read as octal (base 8); otherwise it is read as decimal.

返迴 0,若轉換失敗。

ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

注意: The conversion of the number is performed in the default C locale, regardless of the user's locale. Use QLocale to perform locale-aware conversions between numbers and strings.

該函數在 Qt 6.3 引入。

[noexcept, since 6.3] QByteArrayView QByteArrayView:: trimmed () const

Returns a copy of this byte array view with spacing characters removed from the start and end.

The spacing characters are those for which the standard C++ isspace() 函數返迴 true in the C locale; these are the ASCII characters tabulation '\t', line feed '\n', carriage return '\r', vertical tabulation '\v', form feed '\f', and space ' '.

該函數在 Qt 6.3 引入。

另請參閱 QChar::SpecialCharacter and Spacing Characters .

[constexpr] void QByteArrayView:: truncate ( qsizetype length )

Truncates this byte array view to length length .

如同 *this = first(length) .

注意: 行為未定義當 length < 0 or length > size ().

另請參閱 first (), last (), sliced (), chopped (),和 chop ().

[constexpr noexcept, since 6.7] std::string_view QByteArrayView:: operator std::string_view () const

轉換此 QByteArrayView object to a std::string_view object. The returned view will have the same data pointer and length of this view.

該函數在 Qt 6.7 引入。

[constexpr] char QByteArrayView:: operator[] ( qsizetype n ) const

返迴字符位於位置 n in this byte array view.

行為未定義若 n is negative or not less than size ().

另請參閱 at (), front (),和 back ().

相關非成員

[noexcept] bool operator!= (const QByteArrayView & lhs , const QByteArrayView & rhs )

[noexcept] bool operator< (const QByteArrayView & lhs , const QByteArrayView & rhs )

[noexcept] bool operator<= (const QByteArrayView & lhs , const QByteArrayView & rhs )

[noexcept] bool operator== (const QByteArrayView & lhs , const QByteArrayView & rhs )

[noexcept] bool operator> (const QByteArrayView & lhs , const QByteArrayView & rhs )

[noexcept] bool operator>= (const QByteArrayView & lhs , const QByteArrayView & rhs )

Comparison operators for QByteArrayView .