サーバーの実装は、検出されたすべての IP アドレスのリストを取得し、最初の非ローカル IP を見つけます。それ以外の場合は、デフォルトで localhost を使用します。ローカル ホスト アドレスが表示されている場合は、ネットワークに何かが正しく設定されておらず、Qt が LAN IP を特定できなかったことを示しています。
コメントで @drescherjm が示唆しているように、すべてのインターフェイスで明示的にリッスンできます0.0.0.0
。ipAddress
これを実際に確認するには、次の文字列でステータス ラベルを設定する直前に行を追加する必要があります。
// add this to force the socket to listen on all interfaces
ipAddress = QHostAddress("0.0.0.0").toString();
// or if you have a local static ip and want to be explicit
// ipAddress = QHostAddress("192.168.xxx.xxx").toString();
// followed by the already existing line for setting the text
statusLabel->setText(tr("The server is running on\n\nIP: %1\nport: %2\n\n"
"Run the Fortune Client example now.")
.arg(ipAddress).arg(tcpServer->serverPort()));
ネットワークが正しく設定されていれば、サーバー アプリを実行しているコンピューターを認識できる他のコンピューターは、指定されたポートに接続できるはずです。