QML WebSocket クライアント
QML WebSocket クライアントのサンプルを作成する方法について説明します。
このQML WebSocketクライアントのサンプルでは、QML APIを使用してエコーサーバーへのセキュアおよび非セキュアなWebSocket接続を確立し、接続の開閉を交互に行います。接続が開かれるたびに、メッセージが送信されます。

このサンプルでは、ウェルカムメッセージが表示されたウィンドウが開きます。ウィンドウがクリックされるたびに、外部のエコーサーバーへの 2 つの接続の確立と切断が交互に行われます。使用されるエコーサーバーは ws.ifelse.io にあり、サンプルを動作させるにはインターネット接続が必要です。また、セキュアな接続を機能させるには TLS を有効にする必要があります。 接続が開かれたり閉じられたりすると、`statusChanged`シグナルが`onStatusChanged`ハンドラによって処理されます。ソケットが開かれるたびにメッセージが送信され、ソケットが閉じられるたびにウィンドウにメッセージが記録されます。さらに、`onTextMessageReceived`ハンドラがあり、サーバーから受信したメッセージをウィンドウに記録します。
© 2026 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.