diff options
author | Peter Hartmann <peter.hartmann@nokia.com> | 2009-10-01 08:37:15 (GMT) |
---|---|---|
committer | Peter Hartmann <peter.hartmann@nokia.com> | 2009-10-01 08:42:21 (GMT) |
commit | f289576105f2c560d23d91d4078b832bbd19dc70 (patch) | |
tree | ad8a902a017bfe7c4519612a7dc798ed99877903 /examples/network | |
parent | 9c34f75dedddea2e84432dc6f173389a1814d0f9 (diff) | |
download | Qt-f289576105f2c560d23d91d4078b832bbd19dc70.zip Qt-f289576105f2c560d23d91d4078b832bbd19dc70.tar.gz Qt-f289576105f2c560d23d91d4078b832bbd19dc70.tar.bz2 |
Threaded Fortune server example: fix displayed IP
listen to the first non-local IPv4 address found, as in commit
5e3775ae4c5263a25e63868e8a3f16244e4dde02
Reviewed-by: Aleksandar Babic
Diffstat (limited to 'examples/network')
-rw-r--r-- | examples/network/fortuneserver/server.cpp | 2 | ||||
-rw-r--r-- | examples/network/threadedfortuneserver/dialog.cpp | 15 |
2 files changed, 14 insertions, 3 deletions
diff --git a/examples/network/fortuneserver/server.cpp b/examples/network/fortuneserver/server.cpp index 016fa78..52b7d61 100644 --- a/examples/network/fortuneserver/server.cpp +++ b/examples/network/fortuneserver/server.cpp @@ -74,7 +74,7 @@ Server::Server(QWidget *parent) // if we did not find one, use IPv4 localhost if (ipAddress.isEmpty()) ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); - statusLabel->setText(tr("The server is running on\nIP: \n%1 port:\n%2\n" + 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())); //! [1] diff --git a/examples/network/threadedfortuneserver/dialog.cpp b/examples/network/threadedfortuneserver/dialog.cpp index 51ae0d3..b1ea395 100644 --- a/examples/network/threadedfortuneserver/dialog.cpp +++ b/examples/network/threadedfortuneserver/dialog.cpp @@ -62,9 +62,20 @@ Dialog::Dialog(QWidget *parent) return; } - statusLabel->setText(tr("The server is running on port %1.\n" + QString ipAddress; + QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); + // use the first non-localhost IPv4 address + for (int i = 0; i < ipAddressesList.size(); ++i) { + if (ipAddressesList.at(i) != QHostAddress::LocalHost && + ipAddressesList.at(i).toIPv4Address()) + ipAddress = ipAddressesList.at(i).toString(); + } + // if we did not find one, use IPv4 localhost + if (ipAddress.isEmpty()) + ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); + statusLabel->setText(tr("The server is running on\n\nIP: %1\nport: %2\n\n" "Run the Fortune Client example now.") - .arg(server.serverPort())); + .arg(ipAddress).arg(server.serverPort())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); |