Qt WebChannel ChatClient HTML サンプル

QWebChannel サーバと WebSocket 経由で通信する HTML/JavaScript クライアントです。

ChatClient HTMLは、JavaScript と HTML を使用して実装されたシンプルなQWebChannel クライアントを提供します。

例の実行

例を実行するには、ブラウザでchatclient.html ファイルを開きます。

ウェブチャネル・クライアントの実装

クライアントは、チャットサーバーへのWebSocket接続を初期化し、チャットクライアントを実装するために必要なすべてのシグナル、スロット、プロパティを含むオブジェクトを受け取ります。

ログイン後、クライアントはメソッドsendMessage を呼び出し、シグナルnewMessage を受け取ることで、メッセージを送受信することができます。さらに、userList プロパティは、接続されている他のすべてのクライアントの名前を提供します。リストの内容が変更されると、自動的に更新されます。また、クライアントはサーバーのキープアライブシグナルに応答します。これは、切断されたクライアントを検出し、userList プロパティから削除するために必要です。

この例では、シグナルへの接続 (newMessage)、スロットの呼び出し (sendMessage)、プロパティの変更の処理 (userList) など、基本的な要素がQWebChannel のクライアント JavaScript 実装でどのように使用できるかを示しています。

クライアントはQt WebChannel ChatServer Example で動作します。

サンプルプロジェクト @ code.qt.io

Qt WebChannel ChatServer ExampleおよびQt WebChannel ChatClient QML Applicationも参照して ください。

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