Qt WebChannel 獨立範例

在服務器和運行於瀏覽器的遠程客戶端之間的簡單聊天。

Standalone 演示如何使用 QWebChannel C++ API,與外部客戶端進行通信。它是 C++ 應用程序和運行在默認瀏覽器中的遠程 HTML 客戶機之間的簡單聊天。

運行範例

要運行範例從 Qt Creator ,打開 歡迎 模式,然後選擇範例從 範例 。更多信息,拜訪 構建和運行範例 .

與遠程客戶端通信

C++ 應用程序設置 QWebChannel 實例和發布 Core object over it. For the remote client side, index.html is opened. Both show a dialog with the list of received messages and an input box to send messages to the other end.

The Core 發射 Core::sendText() 信號,當用戶發送消息時。信號被自動傳播到 HTML 客戶機。當用戶在 HTML 端鍵入消息時, Core::receiveText() 被調用。

All communication between the HTML client and the C++ server is done over a WebSocket. The C++ side instantiates a QWebSocketServer 並包裹傳入 QWebSocket 連接在 QWebChannelAbstractTransport 對象。然後,把這些對象連接到 QWebChannel 實例。

文件:

另請參閱 Qt WebChannel JavaScript API .