本页内容

QMaskGenerator Class

QMaskGenerator 类为自定义的 32 位掩码生成器提供了一个抽象基类。更多内容...

头文件: #include <QMaskGenerator>
CMake: find_package(Qt6 REQUIRED COMPONENTS WebSockets)
target_link_libraries(mytarget PRIVATE Qt6::WebSockets)
qmake: QT += websockets
继承自: QObject

公共函数

QMaskGenerator(QObject *parent = nullptr)
virtual ~QMaskGenerator() override
virtual quint32 nextMask() = 0
virtual bool seed() = 0

详细说明

RFC 6455中概述的 WebSockets 规范要求所有从客户端到服务器的通信都必须进行掩码处理。这是为了防止恶意脚本攻击行为不当的代理服务器。 有关良好掩码处理重要性的更多信息,请参阅黄林顺等人撰写的《Talking to Yourself for Fun and Profit》。默认情况下,QWebSocket 使用安全性较高的QRandomGenerator::global()->generate()函数。针对上述文档中提到的攻击,最佳防范措施是通过安全连接(wss://)使用QWebSocket 。 总之,请务必注意,切勿让应用程序中的第三方脚本访问QWebSocket 。

成员函数文档

[explicit] QMaskGenerator::QMaskGenerator(QObject *parent = nullptr)

使用给定的可选参数QObject parent 创建一个新的QMaskGenerator对象。

[override virtual noexcept] QMaskGenerator::~QMaskGenerator()

销毁QMaskGenerator 对象。

[pure virtual] quint32 QMaskGenerator::nextMask()

返回一个新的随机 32 位掩码。其随机性取决于生成该掩码时使用的随机数生成器 (RNG)。

[pure virtual] bool QMaskGenerator::seed()

通过为随机数生成器设置初始化种子来初始化QMaskGenerator 。当未调用seed()方法时,是否使用默认种子或完全不使用种子,取决于子类的具体实现。如果初始化成功,则返回true;否则返回false。

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