如何在没有 webSockets 的情况下使用 QT WebChannel

How use QT WebChannel without webSockets

是否可以在没有 websockets 的情况下使用 QT QWebChannel,但使用 WebKit ICP? 我只找到了使用 webSockets 的示例。

不幸的是,documentation 指出:

It works on all browsers that support Qt WebSockets, [...]. Additionally, a custom transport mechanism can also be implemented using Qt WebSockets to support Qt WebChannel-based communication.

似乎没有 WebSockets 就无法使用它,这将解释为什么您找到的所有示例实际上都在使用它们。

无论如何,它还声明:

The transport mechanism is supported out of the box by the two popular web engines, Qt WebKit 2 and Qt WebEngine (experimental).

尽管它是 实验性的 ,但它看起来像是 WebSockets 的替代品。 实际上,在深入研究链接文档时,我发现 that pageWebKit 它在内部实现了所需的接口,并且可以用来代替 WebSockets,但没有提供示例。

您可以在整个链接页面中找到备用信息,例如据说:

For HTML clients run inside Qt WebKit, you can load the file via qrc:///qtwebchannel/qwebchannel.js. For external clients you will need to copy the file to your webserver.

然后,根据我的理解,在这种情况下不使用 WebSockets,简要描述要在这些客户端上实现相同目标的步骤。

也就是说,在我看来,基于 WebSockets 的解决方案是建议的解决方案,因此您可能应该重新考虑您的架构并使用它们。否则,请准备好处理实验性和记录不佳的功能。