QWebChannelAbstractTransport Class

C++QWebChannel 服务器与 HTML/JS 客户端之间的通信通道。更多

Header: #include <QWebChannelAbstractTransport>
qmake: QT += webchannel
Inherits: QObject

公共函数

QWebChannelAbstractTransport(QObject *parent = nullptr)
virtual ~QWebChannelAbstractTransport() override

公共插槽

virtual void sendMessage(const QJsonObject &message) = 0

信号

void messageReceived(const QJsonObject &message, QWebChannelAbstractTransport *transport)

详细说明

QWebChannel 的用户必须实现该接口,并为每个应连接到QWebChannel 的客户端将其实例连接到QWebChannel 服务器。Qt WebChannel 独立示例展示了如何使用 Qt WebSockets.

注: JSON 消息协议被视为内部协议,可能会随时间推移而改变。

另请参阅 Qt WebChannel 独立示例

成员函数文档

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

用给定的parent 构建一个传输对象。

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

销毁传输对象。

[signal] void QWebChannelAbstractTransport::messageReceived(const QJsonObject &message, QWebChannelAbstractTransport *transport)

从远程客户端接收到新的 JSONmessage 时,必须发出该信号。transport 参数应设置为该传输对象。

[pure virtual slot] void QWebChannelAbstractTransport::sendMessage(const QJsonObject &message)

向远程客户端发送 JSONmessage 。实现方法是将信息序列化,然后将其发送到远程 JavaScript 客户端。

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