本页内容

QHttpHeaderRangeSpec Struct

QHttpHeaderRangeSpec 表示 HTTPRange 和Content-Range 头中使用的单字节范围,RFC 9110 将其称为范围规范。更多内容...

头文件: #include <QHttpHeaderRangeSpec>
CMake: find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
qmake: QT += network
自: Qt 6.12
状态: 技术预览

该结构体处于技术预览阶段,内容可能会有变动。

QHttpHeaderRangeSpec 比较

类别可比较类型
相等性QHttpHeaderRangeSpec

公共函数

bool isValid() const

公共变量

std::optional<qint64> end
std::optional<qint64> start
(since 6.12) size_t qHash(QHttpHeaderRangeSpec key, size_t seed = 0)
(since 6.12) QDebug operator<<(QDebug debug, const QHttpHeaderRangeSpec &range)

详细说明

范围规范有一个可选的起始点和一个可选的结束点,两者均以字节偏移量表示。如果缺少起始点或结束点,则表示为std::nullopt 。

在将范围规范传递给QHttpHeaders::setRangeValues()之前,请使用isValid()来检查该范围规范是否格式正确。

另请参阅 QHttpHeaderRangeSet 、QHttpHeaders::rangeValues() 和QHttpHeaders::setRangeValues()。

成员函数文档

[constexpr noexcept] bool QHttpHeaderRangeSpec::isValid() const

如果范围规范格式正确,则返回true ;否则返回false 。

在以下情况下,范围规范被视为无效:

  • 起始值和结束值均为 `std::nullopt`。
  • 起始值为负数。
  • 结束值为负数。
  • 起始值和结束值均已设置,且起始值大于结束值。

成员变量文档

std::optional<qint64> QHttpHeaderRangeSpec::end

包含该范围的结束字节偏移量;如果未设置结束字节,则为std::nullopt 。一个有起始字节但无结束字节的范围(例如:bytes=500- )表示请求从给定偏移量到资源末尾的所有字节。

另请参见 start 。

std::optional<qint64> QHttpHeaderRangeSpec::start

包含该范围的起始字节偏移量,如果未设置起始位置,则为std::nullopt 。一个未指定起始位置但指定了结束位置的范围(例如,bytes=-500 )表示该资源的最后N个字节。

另请参阅 end 。

相关非成员

[noexcept, since 6.12] size_t qHash(QHttpHeaderRangeSpec key, size_t seed = 0)

返回key 的哈希值,并使用seed 作为计算的种子。

该函数于 Qt 6.12 中引入。

[since 6.12] QDebug operator<<(QDebug debug, const QHttpHeaderRangeSpec &range)

将range 写入debug 流中。

该函数在 Qt 6.12 中引入。

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