Search code examples
htmlqtwebviewwebsocketwebkit

How use QT WebChannel without webSockets


Is possible to use QT QWebChannel without websockets, but using WebKit ICP? I only found examples using webSockets.


Solution

  • Unfortunately, the documentation states that:

    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.

    It seems that you cannot use it without WebSockets, and it would explain why all the examples you find actually use them.

    Anyway, it also states that:

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

    Despite the fact that it is experimental, it looks like an alternative to the WebSockets. Actually, while digging into the linked documentation, I've found that page where it is said about WebKit that it implements internally the required interface and it can be used in place of the WebSockets, but no example is provided.

    You can find spare information all throughout the linked page, as an example it is said that:

    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.

    Then, it follows a brief description of the steps to be done to achieve the same on those clients, as far as I understand by using no WebSockets in this case.

    That said, It seems to me that the solution based on the WebSockets is the suggested one, so probably you should reconsider you architecture and use them. Otherwise, be ready to deal with experimental and poor documented features.