本页内容

QLatin1StringView Class

QLatin1StringView 类为 US-ASCII/Latin-1 编码的字符串字面量提供了一个轻量级的封装。更多内容...

头文件: #include <QLatin1StringView>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

注意:该类中的所有函数均为可重入的。

QLatin1StringView 比较

类别可比较类型描述
strongQLatin1StringView
strongchar16_t、QChar 、QStringView 、QUtf8StringView 、QString 以及 const char16_t *。
strongconst char *、QByteArray 和QByteArrayView 。字节数组数据被解释为 UTF-8。

公共类型

公共函数

QLatin1StringView()
(since 6.3) QLatin1StringView(QByteArrayView str)
QLatin1StringView(const QByteArray &str)
QLatin1StringView(const char *str)
(since 6.4) QLatin1StringView(std::nullptr_t)
QLatin1StringView(const char *first, const char *last)
QLatin1StringView(const char *str, qsizetype size)
QString arg(Args &&... args) const
QLatin1Char at(qsizetype pos) const
QLatin1Char back() const
QLatin1StringView::const_iterator begin() const
QLatin1StringView::const_iterator cbegin() const
QLatin1StringView::const_iterator cend() const
void chop(qsizetype length)
QLatin1StringView chopped(qsizetype length) const
int compare(QChar ch) const
int compare(QChar ch, Qt::CaseSensitivity cs) const
int compare(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
int compare(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
(since 6.5) int compare(QUtf8StringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
(since 6.4) const char *constBegin() const
(since 6.4) const char *constData() const
(since 6.4) const char *constEnd() const
bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool contains(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
(since 6.4) qsizetype count(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
(since 6.4) qsizetype count(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
(since 6.4) qsizetype count(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
QLatin1StringView::const_reverse_iterator crbegin() const
QLatin1StringView::const_reverse_iterator crend() const
const char *data() const
(since 6.4) bool empty() const
QLatin1StringView::const_iterator end() const
bool endsWith(QChar ch) const
bool endsWith(QChar ch, Qt::CaseSensitivity cs) const
bool endsWith(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool endsWith(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
(since 6.4) QLatin1Char first() const
(since 6.0) QLatin1StringView first(qsizetype n) const
QLatin1Char front() const
qsizetype indexOf(QChar c, qsizetype from = 0) const
qsizetype indexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const
qsizetype indexOf(QLatin1StringView l1, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
qsizetype indexOf(QStringView str, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool isEmpty() const
bool isNull() const
(since 6.4) QLatin1Char last() const
(since 6.0) QLatin1StringView last(qsizetype n) const
qsizetype lastIndexOf(QChar c) const
(since 6.3) qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const
qsizetype lastIndexOf(QChar c, qsizetype from) const
qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const
qsizetype lastIndexOf(QLatin1StringView l1, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
qsizetype lastIndexOf(QStringView str, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
(since 6.2) qsizetype lastIndexOf(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
(since 6.2) qsizetype lastIndexOf(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
const char *latin1() const
QLatin1StringView left(qsizetype length) const
(since 6.4) qsizetype length() const
(since 6.8) qsizetype max_size() const
QLatin1StringView mid(qsizetype start, qsizetype length = -1) const
QLatin1StringView::const_reverse_iterator rbegin() const
QLatin1StringView::const_reverse_iterator rend() const
QLatin1StringView right(qsizetype length) const
qsizetype size() const
(since 6.8) QLatin1StringView &slice(qsizetype pos)
(since 6.8) QLatin1StringView &slice(qsizetype pos, qsizetype n)
(since 6.0) QLatin1StringView sliced(qsizetype pos) const
(since 6.0) QLatin1StringView sliced(qsizetype pos, qsizetype n) const
bool startsWith(QChar ch) const
bool startsWith(QChar ch, Qt::CaseSensitivity cs) const
bool startsWith(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool startsWith(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
(since 6.4) double toDouble(bool *ok = nullptr) const
(since 6.4) float toFloat(bool *ok = nullptr) const
(since 6.4) int toInt(bool *ok = nullptr, int base = 10) const
(since 6.4) long toLong(bool *ok = nullptr, int base = 10) const
(since 6.4) qlonglong toLongLong(bool *ok = nullptr, int base = 10) const
(since 6.4) short toShort(bool *ok = nullptr, int base = 10) const
(since 6.0) QString toString() const
(since 6.4) uint toUInt(bool *ok = nullptr, int base = 10) const
(since 6.4) ulong toULong(bool *ok = nullptr, int base = 10) const
(since 6.4) qulonglong toULongLong(bool *ok = nullptr, int base = 10) const
(since 6.4) ushort toUShort(bool *ok = nullptr, int base = 10) const
(since 6.9) QByteArray toUtf8() const
(since 6.0) auto tokenize(Needle &&sep, Flags... flags) const
QLatin1StringView trimmed() const
void truncate(qsizetype length)
QLatin1Char operator[](qsizetype pos) const

静态公共成员

(since 6.8) qsizetype maxSize()
bool operator!=(const QChar&lhs, const QLatin1StringView&rhs)
bool operator!=(const QLatin1StringView&lhs, const QChar&rhs)
bool operator!=(const QLatin1StringView&lhs, const QLatin1StringView&rhs)
bool operator!=(const QLatin1StringView&lhs, const QStringView&rhs)
bool operator!=(const QLatin1StringView&lhs, const char *const&rhs)
bool operator!=(const QStringView&lhs, const QLatin1StringView&rhs)
bool operator!=(const char *const&lhs, const QLatin1StringView&rhs)
bool operator!=(const QLatin1StringView&lhs, const QByteArray&rhs)
(since 6.4) QLatin1StringView operator""_L1(const char*str, size_tsize)
bool operator<(const QChar&lhs, const QLatin1StringView&rhs)
bool operator<(const QLatin1StringView&lhs, const QChar&rhs)
bool operator<(const QLatin1StringView&lhs, const QLatin1StringView&rhs)
bool operator<(const QLatin1StringView&lhs, const QStringView&rhs)
bool operator<(const QLatin1StringView&lhs, const char *const&rhs)
bool operator<(const QStringView&lhs, const QLatin1StringView&rhs)
bool operator<(const char *const&lhs, const QLatin1StringView&rhs)
bool operator<(const QLatin1StringView&lhs, const QByteArray&rhs)
bool operator<=(const QChar&lhs, const QLatin1StringView&rhs)
bool operator<=(const QLatin1StringView&lhs, const QChar&rhs)
bool operator<=(const QLatin1StringView&lhs, const QLatin1StringView&rhs)
bool operator<=(const QLatin1StringView&lhs, const QStringView&rhs)
bool operator<=(const QLatin1StringView&lhs, const char *const&rhs)
bool operator<=(const QStringView&lhs, const QLatin1StringView&rhs)
bool operator<=(const char *const&lhs, const QLatin1StringView&rhs)
bool operator<=(const QLatin1StringView&lhs, const QByteArray&rhs)
bool operator==(const QChar&lhs, const QLatin1StringView&rhs)
bool operator==(const QLatin1StringView&lhs, const QChar&rhs)
bool operator==(const QLatin1StringView&lhs, const QLatin1StringView&rhs)
bool operator==(const QLatin1StringView&lhs, const QStringView&rhs)
bool operator==(const QLatin1StringView&lhs, const char *const&rhs)
bool operator==(const QStringView&lhs, const QLatin1StringView&rhs)
bool operator==(const char *const&lhs, const QLatin1StringView&rhs)
bool operator==(const QLatin1StringView&lhs, const QByteArray&rhs)
bool operator>(const QChar&lhs, const QLatin1StringView&rhs)
bool operator>(const QLatin1StringView&lhs, const QChar&rhs)
bool operator>(const QLatin1StringView&lhs, const QLatin1StringView&rhs)
bool operator>(const QLatin1StringView&lhs, const QStringView&rhs)
bool operator>(const QLatin1StringView&lhs, const char *const&rhs)
bool operator>(const QStringView&lhs, const QLatin1StringView&rhs)
bool operator>(const char *const&lhs, const QLatin1StringView&rhs)
bool operator>(const QLatin1StringView&lhs, const QByteArray&rhs)
bool operator>=(const QChar&lhs, const QLatin1StringView&rhs)
bool operator>=(const QLatin1StringView&lhs, const QChar&rhs)
bool operator>=(const QLatin1StringView&lhs, const QLatin1StringView&rhs)
bool operator>=(const QLatin1StringView&lhs, const QStringView&rhs)
bool operator>=(const QLatin1StringView&lhs, const char *const&rhs)
bool operator>=(const QStringView&lhs, const QLatin1StringView&rhs)
bool operator>=(const char *const&lhs, const QLatin1StringView&rhs)
bool operator>=(const QLatin1StringView&lhs, const QByteArray&rhs)

详细说明

QString 的许多成员函数都进行了重载,以接受 `const char * ` 而不是 `QString`。这包括复制构造函数、赋值运算符、比较运算符,以及诸如 `insert()`、`append()` 和 `prepend()` 等其他各种函数。其中一些函数经过优化,以避免为 `const char * ` 数据构建 `QString ` 对象。例如,假设 `str ` 是 `QString`,

if (str == "auto" || str == "extern"
        || str == "static" || str == "register") {
    //...
}

比

if (str == QString("auto") || str == QString("extern")
        || str == QString("static") || str == QString("register")) {
    //...
}

,因为它不会构建四个临时QString 对象,也不会对字符数据进行深度复制。

然而,并非所有接受const char * 的QString 成员函数都符合这一情况,因此应用程序应假设会创建一个临时对象,例如在

str.append("Hello ").append("World");

定义了QT_NO_CAST_FROM_ASCII 的应用程序(如QString 文档中所解释的)无法访问QString 的const char * API。为了提供一种指定常量Latin-1字符串的高效方法,Qt提供了QLatin1StringView,它只是const char * 的一个非常轻量级的封装。使用QLatin1StringView后,上面的示例代码变为

// Required for using the '_L1' string literal.
using namespace Qt::StringLiterals;
// ...
if (str == "auto"_L1
        || str == "extern"_L1
        || str == "static"_L1
        || str == "register"_L1) {
    //...
}

虽然输入起来稍长一些,但它与第一版代码具有完全相同的优势,并且比使用QString::fromLatin1() 转换 Latin-1 字符串的速度更快。

得益于QString()(QLatin1StringView)构造函数,QLatin1StringView可以在任何需要QString 的地方使用。例如:

QLabel *label = new QLabel("MOD"_L1, this);

注意:如果您 调用带 QLatin1StringView 参数的函数,而 该函数实际上并未重载以接受 QLatin1StringView,则 隐式转换为QString 会触发内存分配——这通常正是您最初使用 QLatin1StringView 想要避免的情况。在这种情况下,使用QStringLiteral 可能是更好的选择。

注意: 如果源代码文件采用Qt 要求的 UTF-8 编码,则 QLatin1StringView 中只能 使用 US-ASCII 字面量。非 US-ASCII 字面量(如QLatin1StringView("é") )将无法正确显示。您可以改用八进制或十六进制表示法:分别是QLatin1StringView("\351") 或QLatin1StringView("\xe9") 。

另请参阅 QString 、QLatin1Char 、QStringLiteral 以及QT_NO_CAST_FROM_ASCII 。

成员类型文档

[alias] QLatin1StringView::const_iterator

另请参阅 iterator 和const_reverse_iterator 。

[alias, since 6.7] QLatin1StringView::const_pointer

[alias, since 6.7] QLatin1StringView::pointer

value_type * 的别名。为兼容 STL 而提供。

这些 typedef 定义首次出现在 Qt 6.7 中。

[alias] QLatin1StringView::const_reference

reference 的别名。为兼容 STL 而提供。

[alias] QLatin1StringView::const_reverse_iterator

另请参阅 reverse_iterator 和const_iterator 。

[alias] QLatin1StringView::difference_type

qsizetype 的别名。为兼容 STL 而提供。

[alias] QLatin1StringView::iterator

QLatin1StringView 不支持可变迭代器,因此这与const_iterator 效果相同。

另请参阅 const_iterator 和reverse_iterator 。

[alias] QLatin1StringView::reference

value_type & 的别名。为兼容 STL 而提供。

[alias] QLatin1StringView::reverse_iterator

QLatin1StringView 不支持可变的反向迭代器,因此这与const_reverse_iterator 效果相同。

另请参阅 const_reverse_iterator 和iterator 。

[alias] QLatin1StringView::size_type

qsizetype 的别名。为兼容 STL 而提供。

注意:在 Qt 6 之前的版本中 ,这是int 的别名,会限制 64 位架构下QLatin1StringView 所能容纳的数据量。

[alias] QLatin1StringView::value_type

const char 的别名。为兼容 STL 而提供。

成员函数文档

[constexpr noexcept] QLatin1StringView::QLatin1StringView()

创建一个 QLatin1StringView 对象,用于存储一个nullptr 。

另请参阅 data()、isEmpty()、isNull() 以及Distinction Between Null and Empty Strings 。

[explicit constexpr noexcept, since 6.3] QLatin1StringView::QLatin1StringView(QByteArrayView str)

创建一个 QLatin1StringView 对象,将其作为str 的视图。

字符串数据不会被复制。调用方必须能够保证,只要 QLatin1StringView 对象存在,str 所指向的数据就不会被删除或修改。大小直接从str 获取,且不检查空终止符。

注意: 字节数组中的任何空字节('\0')都将被包含在此字符串中; 如果该字符串被QString 函数使用,这些空字节将被转换为 Unicode 空字符(U+0000)。

该函数在 Qt 6.3 中引入。

另请参阅 latin1()。

[explicit noexcept] QLatin1StringView::QLatin1StringView(const QByteArray &str)

创建一个 QLatin1StringView 对象,将其作为str 的视图。

字符串数据不会被复制。调用方必须确保在 QLatin1StringView 对象存在期间,str 不会被删除或修改。

另请参阅 latin1()。

[explicit constexpr noexcept] QLatin1StringView::QLatin1StringView(const char *str)

创建一个 QLatin1StringView 对象,用于存储 `str`。

字符串数据不会被复制。调用方必须能够保证,只要 QLatin1StringView 对象存在,str 就不会被删除或修改。

另请参阅 latin1()。

[constexpr noexcept, since 6.4] QLatin1StringView::QLatin1StringView(std::nullptr_t)

创建一个 QLatin1StringView 对象,用于存储一个nullptr 。

该函数在 Qt 6.4 中引入。

另请参阅 data()、isEmpty()、isNull() 以及Distinction Between Null and Empty Strings 。

[constexpr] QLatin1StringView::QLatin1StringView(const char *first, const char *last)

构建一个 QLatin1StringView 对象,用于存储字符串first ,其长度为 (last -first)。

在该 Latin-1 字符串对象的生命周期内,[first,last) 范围必须始终有效。

如果last 也是nullptr ,则将nullptr 作为first 传递是安全的,并将返回一个空的 Latin-1 字符串。

如果last 位于first 之前,且first 为nullptr 而last 不是,或者last - first > INT_MAX ,则行为未定义。

[constexpr noexcept] QLatin1StringView::QLatin1StringView(const char *str, qsizetype size)

创建一个 QLatin1StringView 对象,该对象使用size 存储str 。

字符串数据不会被复制。调用方必须能够保证,只要 QLatin1StringView 对象存在,str 就不会被删除或修改。

注意: 字节数组中的任何空字节('\0')都将包含在此字符串中; 如果该字符串被QString 使用,这些空字节将被转换为 Unicode 空字符(U+0000)。此行为与 Qt 5.x 不同。

另请参阅 latin1()。

template <typename... Args> QString QLatin1StringView::arg(Args &&... args) const

将该字符串中所有%N 替换为args 中的相应参数。这些参数并非按位置对应:args 中的第一个参数将%N 替换为最低的N (所有情况),args 中的第二个参数将%N 替换为次低的N ,以此类推。

Args 可以由任何能隐式转换为QAnyStringView 的内容组成。

注意:在 Qt 6.9 之前的版本中,QAnyStringView 以及 UTF-8 字符串(QUtf8StringView 、QByteArray 、QByteArrayView 、const char8_t* 等)不被支持作为args 。

另请参阅 QString::arg()。

[constexpr] QLatin1Char QLatin1StringView::at(qsizetype pos) const

返回该对象中位于位置pos 处的字符。

注意:此 函数不进行错误检查。当pos < 0 或pos >=size() 时,行为未定义。

另请参阅 operator[]()。

[constexpr] QLatin1Char QLatin1StringView::back() const

返回字符串中的最后一个字符。与at(size() - 1) 相同。

提供此函数是为了兼容 STL。

警告: 对空字符串调用 此函数将导致未定义行为。

另请参阅 front()、at() 和operator[]()。

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

返回一个指向字符串中第一个字符的常量STL 风格迭代器。

提供此函数是为了兼容 STL。

另请参阅 end()、cbegin()、rbegin() 以及data()。

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

与begin()相同。

提供此函数是为了与 STL 兼容。

另请参阅 cend()、begin()、crbegin() 以及data()。

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

与end() 相同。

提供此函数是为了与 STL 兼容。

另请参阅 cbegin()、end() 和crend()。

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

将该字符串截断length 个字符。

与 `*this = left(size() - length)` 相同。

注意: 当length < 0 或length >size() 时,行为未定义。

另请参阅 sliced()、first()、last()、chopped()、truncate() 以及slice()。

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

返回从该对象开头开始,长度为size() -length 的子字符串。

与left(size() - length) 相同。

注意: 当length < 0 或length >size() 时,行为未定义。

另请参阅 sliced()、first()、last()、chop()、truncate() 以及slice()。

[constexpr noexcept] int QLatin1StringView::compare(QChar ch) const

[noexcept] int QLatin1StringView::compare(QChar ch, Qt::CaseSensitivity cs) const

[noexcept] int QLatin1StringView::compare(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[noexcept] int QLatin1StringView::compare(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

分别将此字符串视图与 UTF-16 字符串视图str 、Latin-1 字符串视图l1 或字符ch 进行比较。如果该字符串小于str 、l1 或ch ,则返回负整数;如果大于str 、l1 或ch ,则返回正整数;若两者相等,则返回零。

如果cs 的值为Qt::CaseSensitive (默认值),则搜索区分大小写;否则,搜索不区分大小写。

另请参阅 operator==()、operator<() 和operator>()。

[noexcept, since 6.5] int QLatin1StringView::compare(QUtf8StringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

将此字符串视图与str 进行比较:如果此字符串视图小于str ,则返回一个负整数;如果大于str ,则返回一个正整数;如果两者相等,则返回零。

如果cs 等于Qt::CaseSensitive (默认值),则比较区分大小写;否则,比较不区分大小写。

该函数在 Qt 6.5 中引入。

另请参见 operator==()、operator<() 和operator>()。

[constexpr noexcept, since 6.4] const char *QLatin1StringView::constBegin() const

与 `begin()` 相同。

提供此函数是为了与其他 Qt 容器保持兼容性。

该函数在 Qt 6.4 中引入。

另请参见 constEnd()、begin()、cbegin() 和data()。

[constexpr noexcept, since 6.4] const char *QLatin1StringView::constData() const

返回该对象所引用的 Latin-1 字符串的起始位置。

提供此函数是为了与其他 Qt 容器保持兼容性。

该函数于 Qt 6.4 中引入。

另请参阅 ` data()`。

[constexpr noexcept, since 6.4] const char *QLatin1StringView::constEnd() const

与end() 相同。

提供此函数是为了与其他 Qt 容器保持兼容性。

该函数在 Qt 6.4 中引入。

另请参阅 constBegin()、end()、cend() 和crend()。

[noexcept] bool QLatin1StringView::contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[noexcept] bool QLatin1StringView::contains(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[noexcept] bool QLatin1StringView::contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

如果该 Latin-1 字符串视图中包含由str 表示的 UTF-16 字符串、由l1 表示的 Latin-1 字符串,或者字符ch (分别对应上述情况),则返回true ;否则返回false 。

如果cs 为Qt::CaseSensitive (默认值),则搜索区分大小写;否则,搜索不区分大小写。

另请参阅 indexOf()、QStringView::contains()、QStringView::indexOf( ) 和QString::indexOf( )。

[noexcept, since 6.4] qsizetype QLatin1StringView::count(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[since 6.4] qsizetype QLatin1StringView::count(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[since 6.4] qsizetype QLatin1StringView::count(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

返回该字符串视图中,由str 显示的 UTF-16 字符串、由l1 显示的 Latin-1 字符串,或字符ch 各自出现的次数(可能存在重叠)。

如果cs 为Qt::CaseSensitive (默认值),则搜索区分大小写;否则,搜索不区分大小写。

这些函数在 Qt 6.4 中引入。

另请参阅 contains() 和indexOf()。

[noexcept] QLatin1StringView::const_reverse_iterator QLatin1StringView::crbegin() const

与rbegin()相同。

提供此函数是为了兼容 STL。

另请参阅 crend()、rbegin() 以及cbegin()。

[noexcept] QLatin1StringView::const_reverse_iterator QLatin1StringView::crend() const

与rend()相同。

提供此函数是为了兼容 STL。

另请参见 crbegin()、rend() 和cend()。

[constexpr noexcept] const char *QLatin1StringView::data() const

返回此对象所引用的 Latin-1 字符串的开头。

[constexpr noexcept, since 6.4] bool QLatin1StringView::empty() const

返回该对象所引用的 Latin-1 字符串是否为空(size() == 0 )。

提供此函数是为了兼容 STL。

该函数于 Qt 6.4 版本中引入。

另请参阅 isEmpty()、isNull() 和size()。

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

返回一个指向字符串中最后一个字符之后位置的 constSTL 风格迭代器。

提供此函数是为了兼容 STL。

另请参阅 begin()、cend() 和rend()。

[constexpr noexcept] bool QLatin1StringView::endsWith(QChar ch) const

[noexcept] bool QLatin1StringView::endsWith(QChar ch, Qt::CaseSensitivity cs) const

[noexcept] bool QLatin1StringView::endsWith(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[noexcept] bool QLatin1StringView::endsWith(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

如果此 Latin-1 字符串视图以 UTF-16 字符串str 、通过l1 显示的 Latin-1 字符串,或字符ch 结尾,则返回true ;否则返回false 。

如果cs 为Qt::CaseSensitive (默认值),则搜索区分大小写;否则,搜索不区分大小写。

另请参阅 startsWith()。

[constexpr, since 6.4] QLatin1Char QLatin1StringView::first() const

返回字符串中的第一个字符。与 `at(0) ` 或 `front()` 相同。

提供此函数是为了与其他 Qt 容器保持兼容性。

警告: 对空字符串调用 此函数将导致未定义行为。

该函数于 Qt 6.4 中引入。

另请参见 last()、front() 和back()。

[constexpr, since 6.0] QLatin1StringView QLatin1StringView::first(qsizetype n) const

返回一个 Latin-1 字符串视图,其中包含该字符串视图的前n 个字符。

注意: 当n < 0 或n >size() 时,行为未定义。

该函数在 Qt 6.0 中引入。

另请参阅 last()、startsWith()、chopped()、chop()、truncate() 和slice()。

[constexpr] QLatin1Char QLatin1StringView::front() const

返回字符串中的第一个字符。与 `at(0)` 相同。

提供此函数是为了兼容 STL。

警告: 对空字符串调用 此函数将导致未定义行为。

另请参阅 back()、at() 和operator[]()。

[noexcept] qsizetype QLatin1StringView::indexOf(QChar c, qsizetype from = 0) const

[noexcept] qsizetype QLatin1StringView::indexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const

[noexcept] qsizetype QLatin1StringView::indexOf(QLatin1StringView l1, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[noexcept] qsizetype QLatin1StringView::indexOf(QStringView str, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

返回在此 Latin-1 字符串视图中,UTF-16 字符串(由 `str` 表示)、Latin-1 字符串(由 `l1` 表示)或字符 `ch`(分别)首次出现时的索引位置,从索引位置 `from` 开始向前搜索。如果分别未找到 `str`、`l1 ` 或 `c `,则返回 -1。

如果cs 的值为Qt::CaseSensitive (默认值),则搜索区分大小写;否则,搜索不区分大小写。

如果from 为 -1,则从最后一个字符开始搜索;如果为 -2,则从倒数第二个字符开始搜索,以此类推。

另请参阅 QString::indexOf()。

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

返回该对象所引用的 Latin-1 字符串是否为空(size() == 0 )。

另请参阅 isNull() 和size()。

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

返回此对象所引用的 Latin-1 字符串是否为空(data() == nullptr )。

另请参阅 isEmpty() 和data()。

[constexpr, since 6.4] QLatin1Char QLatin1StringView::last() const

返回字符串中的最后一个字符。与at(size() - 1) 或back()的效果相同。

提供此函数是为了与其他 Qt 容器保持兼容。

警告: 对空字符串调用 此函数将导致未定义行为。

该函数自 Qt 6.4 起引入。

另请参阅 first()、back() 和front()。

[constexpr, since 6.0] QLatin1StringView QLatin1StringView::last(qsizetype n) const

返回一个 Latin-1 字符串视图,其中包含该字符串视图的最后n 个字符。

注意: 当n < 0 或n >size() 时,行为未定义。

该函数在 Qt 6.0 中引入。

另请参见 first()、endsWith()、chopped()、chop()、truncate() 以及slice()。

[noexcept] qsizetype QLatin1StringView::lastIndexOf(QChar c) const

[noexcept, since 6.3] qsizetype QLatin1StringView::lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const

[noexcept] qsizetype QLatin1StringView::lastIndexOf(QChar c, qsizetype from) const

[noexcept] qsizetype QLatin1StringView::lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const

[noexcept] qsizetype QLatin1StringView::lastIndexOf(QLatin1StringView l1, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[noexcept] qsizetype QLatin1StringView::lastIndexOf(QStringView str, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

返回在此 Latin-1 字符串视图中,str 所表示的 UTF-16 字符串、l1 所表示的 Latin-1 字符串或ch 所表示的字符最后一次出现的位置索引,从索引位置from 开始向后搜索;如果分别未找到str 、l1 或ch ,则返回 -1。

如果from 为-1,则从最后一个字符开始搜索;如果为-2,则从倒数第二个字符开始,依此类推。

如果cs 为Qt::CaseSensitive (默认值),则搜索区分大小写;否则,搜索不区分大小写。

注意:当 搜索长度为 0 的str 或l1时, 即使通常认为-1 是从字符串末尾开始搜索的,但通过负值from ,数据末尾的匹配结果也会被排除在搜索之外:末尾的匹配结果位于最后一个字符之后,因此会被排除。 若要包含此类最终的空匹配,可为from 指定正值,或完全省略from 参数。

另请参阅 indexOf()、QStringView::lastIndexOf()、QStringView::indexOf() 以及QString::indexOf()。

[noexcept, since 6.2] qsizetype QLatin1StringView::lastIndexOf(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[noexcept, since 6.2] qsizetype QLatin1StringView::lastIndexOf(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

返回在此 Latin-1 字符串视图中,由 `str ` 识别的 UTF-16 字符串或由 `l1` 识别的 Latin-1 字符串最后一次出现的位置索引。如果分别未找到 `str ` 或 `l1 `,则返回 -1。

如果cs 为Qt::CaseSensitive (默认值),则搜索区分大小写;否则,搜索不区分大小写。

这些函数是在 Qt 6.2 中引入的。

[constexpr noexcept] const char *QLatin1StringView::latin1() const

返回该对象所引用的 Latin-1 字符串的起始位置。

[constexpr] QLatin1StringView QLatin1StringView::left(qsizetype length) const

如果你确定 `length ` 不会超出范围,请在新代码中改用 `first()`,因为它的执行速度更快。

返回此 Latin-1 字符串视图中从位置 0 开始、长度为length 的子字符串。

如果length 大于或等于size(),或者小于零,则返回整个 Latin-1 字符串视图。

另请参见 first()、last()、sliced()、startsWith()、chopped()、chop()、truncate() 和slice()。

[constexpr noexcept, since 6.4] qsizetype QLatin1StringView::length() const

与size() 相同。

提供此函数是为了与其他 Qt 容器保持兼容性。

该函数于 Qt 6.4 中引入。

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

该函数返回字符串视图理论上可表示的元素最大数量。实际上,该数量可能要小得多,具体取决于系统可用的内存大小。

该函数于 Qt 6.8 版本中引入。

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

提供此函数是为了与 STL 兼容。

返回maxSize()。

该函数在 Qt 6.8 中引入。

[constexpr] QLatin1StringView QLatin1StringView::mid(qsizetype start, qsizetype length = -1) const

返回此 Latin-1 字符串视图中,从位置start 开始、长度为length 的子字符串。

如果已知start 和length 不会超出范围,请在新的代码中改用sliced(),因为它的执行速度更快。

如果start 超出了该字符串视图的长度,则返回一个空的 Latin-1 字符串视图。如果该字符串视图中从start 开始可用的字符少于length 个,或者length 为负数(默认值),则该函数返回从start 开始的所有可用字符。

另请参阅 first()、last()、sliced()、chopped()、chop()、truncate() 以及slice() 函数。

[noexcept] QLatin1StringView::const_reverse_iterator QLatin1StringView::rbegin() const

返回一个指向字符串中第一个字符(按反向顺序)的常量STL 风格反向迭代器。

提供此函数是为了兼容 STL。

另请参阅 rend()、crbegin() 和begin()。

[noexcept] QLatin1StringView::const_reverse_iterator QLatin1StringView::rend() const

返回一个STL 风格的反向迭代器,该迭代器指向字符串中最后一个字符之后的第一个位置,且按反向顺序。

提供此函数是为了与 STL 兼容。

另请参阅 rbegin()、crend() 以及end()。

如果你确定length 不会超出数组范围,请在新代码中改用last(),因为它的执行速度更快。

返回此 Latin-1 字符串视图中,从位置size() -length 开始、长度为length 的子字符串。

如果length 大于或等于size(),或者小于零,则返回整个 Latin-1 字符串视图。

另请参阅 first()、last()、sliced()、endsWith()、chopped()、chop()、truncate() 和slice()。

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

返回该对象所引用的 Latin-1 字符串的长度。

注意:在 Qt 6 之前的版本中 ,该函数返回int ,这会限制 64 位架构下QLatin1StringView 中可存储的数据量。

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

修改此 Latin-1 字符串视图,使其从位置pos 开始,并延伸至其末尾。

注意: 当pos < 0 或pos >size() 时,行为未定义。

该函数在 Qt 6.8 中引入。

另请参阅 sliced()、first()、last()、chopped()、chop() 和truncate()。

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

将此 Latin-1 字符串视图修改为从位置pos 开始,并向后延伸n 个字符。

注意: 当pos < 0、n < 0 或pos + n > size() 时,行为未定义。

这是一个重载函数。

该函数在 Qt 6.8 中引入。

另请参阅 sliced()、first()、last()、chopped()、chop()和truncate()。

[constexpr, since 6.0] QLatin1StringView QLatin1StringView::sliced(qsizetype pos) const

返回一个从该字符串视图的pos 位置开始、并延伸至其末尾的Latin-1字符串视图。

注意: 当 `pos < 0` 或 `pos >size()` 时,行为 未定义。

该函数在 Qt 6.0 中引入。

另请参阅 first()、last()、chopped()、chop()、truncate() 以及slice()。

[constexpr, since 6.0] QLatin1StringView QLatin1StringView::sliced(qsizetype pos, qsizetype n) const

返回一个 Latin-1 字符串视图,该视图指向该字符串视图中从位置pos 开始的n 个字符。

注意: 当pos < 0、n < 0 或pos + n > size() 时,行为未定义。

该函数于 Qt 6.0 中引入。

另请参阅 first()、last()、chopped()、chop()、truncate()和slice()。

[constexpr noexcept] bool QLatin1StringView::startsWith(QChar ch) const

[noexcept] bool QLatin1StringView::startsWith(QChar ch, Qt::CaseSensitivity cs) const

[noexcept] bool QLatin1StringView::startsWith(QLatin1StringView l1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

[noexcept] bool QLatin1StringView::startsWith(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

如果该 Latin-1 字符串视图以 UTF-16 字符串(由str 表示)、Latin-1 字符串(由l1 表示)或字符ch 开头,则返回true ;否则返回false 。

如果cs 为Qt::CaseSensitive (默认值),则搜索区分大小写;否则,搜索不区分大小写。

另请参阅 endsWith()。

[since 6.4] double QLatin1StringView::toDouble(bool *ok = nullptr) const

[since 6.4] float QLatin1StringView::toFloat(bool *ok = nullptr) const

返回将该QLatin1StringView 转换为相应的浮点数后的结果。

如果转换发生溢出,则返回无穷大;如果因其他原因(例如下溢)导致转换失败,则返回 0.0。

如果 `ok ` 不是 `nullptr`,则通过将 `*ok ` 设置为 `false` 来报告失败,通过将 `*ok ` 设置为 `true` 来报告成功。

警告: QLatin1StringView 的内容 只能包含有效的数字字符,包括正负号、科学记数法中使用的字符 e 以及小数点。包含单位或其他字符会导致转换错误。

注意: 数字的转换 是在默认的 C 区域设置下进行的,与用户的区域设置无关。请使用QLocale 在数字和字符串之间进行支持区域设置的转换。

该函数会忽略开头和结尾的空格字符。

这些函数在 Qt 6.4 中引入。

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

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

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

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

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

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

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

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

返回将该QLatin1StringView 转换为相应数值的结果,转换时采用基数base (默认值为10)。支持基数0以及2至36,其中大于9的数字使用字母表示;A代表10,B代表11,依此类推。

如果 `base ` 为 0,且 Latin-1 字符串视图以以下形式开头时,将根据以下规则(按此顺序)自动确定进制:

  • "0x",则其余部分被视为十六进制(基数 16)
  • "0b",则其余部分被视为二进制(基数 2)
  • "0",则将其余部分视为八进制(基数8)
  • 否则将其视为十进制

如果转换失败,则返回 0。

如果 `ok ` 不是 `nullptr`,则通过将 `*ok ` 设置为 `false` 来报告失败,通过将 `*ok ` 设置为 `true` 来报告成功。

注意: 数字的转换是在默认的 C 区域设置下进行的,与用户的区域设置无关。若要在数字和字符串之间进行考虑区域设置的转换,请使用QLocale 。

该函数会忽略数字前后的空格字符。

注意: 对“0b”前缀的支持 是在 Qt 6.4 中添加的。

这些函数在 Qt 6.4 中引入。

[since 6.0] QString QLatin1StringView::toString() const

将此 Latin-1 字符串转换为QString 。等同于

return QString(*this);

该函数在 Qt 6.0 中引入。

另请参阅 toUtf8()。

[since 6.9] QByteArray QLatin1StringView::toUtf8() const

返回字符串的 UTF-8 表示形式,即 `QByteArray`。与先转换为 `QString` 相比,此函数的效率更高。

该函数在 Qt 6.9 中引入。

另请参阅 toString() 和QString::toUtf8()。

[constexpr noexcept(...), since 6.0] template <typename Needle, typename... Flags> auto QLatin1StringView::tokenize(Needle &&sep, Flags... flags) const

在出现sep 的位置将字符串拆分为子字符串视图,并返回这些字符串的懒序列。

等同于

return QStringTokenizer{std::forward<Needle>(sep), flags...};

,不同之处在于它即使在编译器未启用 C++17 类模板参数推导 (CTAD) 的情况下也能正常工作。

有关 `sep ` 和 `flags ` 如何协同作用形成结果,请参阅 `QStringTokenizer `。

注意:虽然 该函数返回QStringTokenizer ,但您绝、对、不、要显式命名其模板参数。如果您可以使用 C++17 类模板参数推导 (CTAD),则可以编写

QStringTokenizer result = sv.tokenize(sep);

(无需模板参数)。若无法使用 C++17 CTAD,则必须仅将返回值存储在auto 变量中:

auto result = sv.tokenize(sep);

这是因为QStringTokenizer 的模板参数与其返回的特定tokenize()重载之间存在非常微妙的依赖关系,且这些参数通常并不对应于分隔符所使用的类型。

这些函数是在 Qt 6.0 中引入的。

注意: 当 `noexcept(qTokenize(std::declval<const QLatin1StringView &>(), std::forward<Needle>(needle), flags...)) ` 为 `true()` 重载时,该函数 为 `noexcept`。

另请参阅 QStringTokenizer 和qTokenize()。

[noexcept] QLatin1StringView QLatin1StringView::trimmed() const

去除首尾空格,并返回结果。

空格指任何使QChar::isSpace()返回true 的字符。这包括ASCII字符'\t'、'\n'、'\v'、'\f'、'\r'以及' '。

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

将该字符串截断至长度length 。

与*this = left(length) 相同。

注意: 当length < 0 或length >size() 时,行为未定义。

另请参阅 sliced()、first()、last()、chopped() 和chop()。

[constexpr] QLatin1Char QLatin1StringView::operator[](qsizetype pos) const

返回该对象中位于位置pos 处的字符。

注意:此 函数不进行错误检查。当pos < 0 或pos >=size() 时,行为未定义。

另请参阅 at()。

相关的非成员

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

如果字符lhs 在词法上不等同于字符串rhs ,则返回true ;否则返回false 。

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

如果字符串lhs 与字符rhs 在词法上不相等,则返回true ;否则返回false 。

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

如果字符串lhs 与字符串rhs 在词法上不相同,则返回true ;否则返回false 。

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

如果字符串lhs 在词法上不等于字符串视图rhs ,则返回true ;否则返回false 。

[noexcept] bool operator!=(const QLatin1StringView &lhs, const char *const &rhs)

如果字符串lhs 与 const char 指针rhs 不相等,则返回true ;否则返回false 。

常量字符指针rhs 将被转换为字符串QUtf8StringView 。

您可以在编译应用程序时通过定义QT_NO_CAST_FROM_ASCII 来禁用此运算符。例如,如果您希望确保所有用户可见的字符串都通过QObject::tr() 处理,这将非常有用。

另请参阅 Comparing Strings 。

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

如果字符串视图 `lhs ` 与字符串 `rhs` 在词法上不相同,则返回 `true `;否则返回 `false`。

[noexcept] bool operator!=(const char *const &lhs, const QLatin1StringView &rhs)

如果常量字符指针 `lhs ` 与字符串 `rhs` 在词法上不相同,则返回 `true `;否则返回 `false`。

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

rhs 字节数组会被转换为QUtf8StringView 。

您可以在编译应用程序时通过定义QT_NO_CAST_FROM_ASCII 来禁用此运算符。例如,如果您希望确保所有用户可见的字符串都经过QObject::tr() 处理,这将非常有用。

该函数重载了QLatin1StringView::operator!=()。

[constexpr noexcept, since 6.4] QLatin1StringView operator""_L1(const char *str, size_t size)

一个字面量运算符,它将字符串字面量str 的前size 个字符转换为QLatin1StringView 。

以下代码创建一个QLatin1StringView :

using namespace Qt::StringLiterals;

auto str = "hello"_L1;

该函数在 Qt 6.4 中引入。

另请参阅 Qt::Literals::StringLiterals 。

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

如果字符lhs 在词法上小于字符串rhs ,则返回true ;否则返回false 。

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

如果字符串lhs 在词法意义上小于字符rhs ,则返回true ;否则返回false 。

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

如果字符串lhs 在词法上小于字符串rhs ,则返回true ;否则返回false 。

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

如果字符串lhs 在词法上小于字符串视图rhs ,则返回true ;否则返回false 。

[noexcept] bool operator<(const QLatin1StringView &lhs, const char *const &rhs)

如果字符串lhs 在字面意义上小于const char指针rhs ,则返回true ;否则返回false 。

常量字符指针rhs 将被转换为字符串QUtf8StringView 。

您可以在编译应用程序时通过定义QT_NO_CAST_FROM_ASCII 来禁用此运算符。例如,如果您希望确保所有对用户可见的字符串都经过QObject::tr() 处理,这将非常有用。

另请参阅 Comparing Strings 。

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

如果字符串视图 `lhs ` 在词法上小于字符串 `rhs`,则返回 `true `;否则返回 `false`。

[noexcept] bool operator<(const char *const &lhs, const QLatin1StringView &rhs)

如果常量字符指针 `lhs ` 在词法上小于字符串 `rhs`,则返回 `true `;否则返回 `false`。

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

rhs 字节数组会被转换为QUtf8StringView 。

您可以在编译应用程序时定义 `QT_NO_CAST_FROM_ASCII ` 来禁用此运算符。例如,如果您希望确保所有对用户可见的字符串都经过 `QObject::tr()` 处理,这将非常有用。

这是一个重载函数。

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

如果字符lhs 在词法上小于或等于字符串rhs ,则返回true ;否则返回false 。

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

如果字符串lhs 在词法上小于或等于字符rhs ,则返回true ;否则返回false 。

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

如果字符串lhs 在词法上小于或等于字符串rhs ,则返回true ;否则返回false 。

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

如果字符串lhs 在词法上小于或等于字符串viewrhs ,则返回true ;否则返回false 。

[noexcept] bool operator<=(const QLatin1StringView &lhs, const char *const &rhs)

如果字符串lhs 在字面量顺序上小于或等于 const char 指针rhs ,则返回true ;否则返回false 。

常量字符指针rhs 将被转换为QUtf8StringView 。

您可以在编译应用程序时通过定义QT_NO_CAST_FROM_ASCII 来禁用此运算符。例如,如果您希望确保所有用户可见的字符串都通过QObject::tr() 处理,这将非常有用。

另请参阅 Comparing Strings 。

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

如果字符串视图 `lhs ` 在词法上小于或等于字符串 `rhs`,则返回 `true `;否则返回 `false`。

[noexcept] bool operator<=(const char *const &lhs, const QLatin1StringView &rhs)

如果常量字符指针 `lhs ` 在词法上小于或等于字符串 `rhs`,则返回 `true `;否则返回 `false`。

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

rhs 字节数组会被转换为QUtf8StringView 。

您可以在编译应用程序时通过定义 `QT_NO_CAST_FROM_ASCII ` 来禁用此运算符。例如,如果您希望确保所有用户可见的字符串都经过 `QObject::tr()` 处理,此方法便十分有用。

这是一个重载函数。

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

如果字符lhs 与字符串rhs 在词法上相等,则返回true ;否则返回false 。

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

如果字符串lhs 与字符rhs 在词法上相等,则返回true ;否则返回false 。

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

如果字符串lhs 与字符串rhs 在词法上相等,则返回true ;否则返回false 。

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

如果字符串lhs 与字符串视图rhs 在词法上相等,则返回true ;否则返回false 。

[noexcept] bool operator==(const QLatin1StringView &lhs, const char *const &rhs)

如果字符串lhs 与 const char 指针rhs 相等,则返回true ;否则返回false 。

rhs 常量字符指针会被转换为QUtf8StringView 。

您可以在编译应用程序时通过定义QT_NO_CAST_FROM_ASCII 来禁用此运算符。例如,如果您希望确保所有用户可见的字符串都通过QObject::tr() 处理,这将非常有用。

另请参阅 Comparing Strings 。

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

如果字符串视图 `lhs ` 与字符串 `rhs` 在词法上相等,则返回 `true `;否则返回 `false`。

[noexcept] bool operator==(const char *const &lhs, const QLatin1StringView &rhs)

如果常量字符指针 `lhs ` 与字符串 `rhs` 在词法上相等,则返回 `true `;否则返回 `false`。

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

rhs 字节数组会被转换为QUtf8StringView 。

您可以在编译应用程序时通过定义 `QT_NO_CAST_FROM_ASCII ` 来禁用此运算符。例如,如果您希望确保所有用户可见的字符串都经过 `QObject::tr()` 处理,这会很有用。

这是一个重载函数。

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

如果字符lhs 在词法上大于字符串rhs ,则返回true ;否则返回false 。

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

如果字符串lhs 在词法上大于字符rhs ,则返回true ;否则返回false 。

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

如果字符串lhs 在词法意义上大于字符串rhs ,则返回true ;否则返回false 。

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

如果字符串lhs 在词法上大于字符串视图rhs ,则返回true ;否则返回false 。

[noexcept] bool operator>(const QLatin1StringView &lhs, const char *const &rhs)

如果字符串 `lhs ` 在字面量意义上大于 `const char` 指针 `rhs`,则返回 `true `;否则返回 `false`。

常量字符指针rhs 将被转换为字符串QUtf8StringView 。

您可以在编译应用程序时通过定义 `QT_NO_CAST_FROM_ASCII ` 来禁用此运算符。例如,如果您希望确保所有用户可见的字符串都通过 `QObject::tr()` 处理,此操作将非常有用。

另请参阅 Comparing Strings 。

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

如果字符串视图lhs 在词法意义上大于字符串rhs ,则返回true ;否则返回false 。

[noexcept] bool operator>(const char *const &lhs, const QLatin1StringView &rhs)

如果常量字符指针 `lhs ` 的词法大小大于字符串 `rhs`,则返回 `true `;否则返回 `false`。

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

rhs 字节数组会被转换为QUtf8StringView 。

您可以在编译应用程序时通过定义 `QT_NO_CAST_FROM_ASCII ` 来禁用此运算符。例如,如果您希望确保所有用户可见的字符串都经过 `QObject::tr()` 处理,这将非常有用。

这是一个重载函数。

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

如果字符lhs 在词法上大于或等于字符串rhs ,则返回true ;否则返回false 。

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

如果字符串lhs 的词法大小大于或等于字符rhs ,则返回true ;否则返回false 。

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

如果字符串 `lhs ` 的词法大小大于或等于字符串 `rhs`,则返回 `true `;否则返回 `false`。

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

如果字符串lhs 在词法意义上大于或等于字符串viewrhs ,则返回true ;否则返回false 。

[noexcept] bool operator>=(const QLatin1StringView &lhs, const char *const &rhs)

如果字符串lhs 在字面量意义上大于或等于 const char 指针rhs ,则返回true ;否则返回false 。

常量字符指针rhs 将被转换为字符串QUtf8StringView 。

您可以在编译应用程序时定义QT_NO_CAST_FROM_ASCII 来禁用此运算符。例如,如果您希望确保所有用户可见的字符串都通过QObject::tr() 处理,此方法会很有用。

另请参阅 Comparing Strings 。

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

如果字符串视图 `lhs ` 在词法上大于或等于字符串 `rhs`,则返回 `true `;否则返回 `false`。

[noexcept] bool operator>=(const char *const &lhs, const QLatin1StringView &rhs)

如果常量字符指针 `lhs ` 在词法上大于或等于字符串 `rhs`,则返回 `true `;否则返回 `false`。

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

rhs 字节数组会被转换为QUtf8StringView 。

您可以在编译应用程序时通过定义 `QT_NO_CAST_FROM_ASCII ` 来禁用此运算符。例如,如果您希望确保所有用户可见的字符串都经过 `QObject::tr()` 处理,此方法会非常有用。

这是一个重载函数。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.