summaryrefslogtreecommitdiffstats
path: root/examples/network
diff options
context:
space:
mode:
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/fortuneserver/server.cpp2
-rw-r--r--examples/network/threadedfortuneserver/dialog.cpp15
2 files changed, 14 insertions, 3 deletions
diff --git a/examples/network/fortuneserver/server.cpp b/examples/network/fortuneserver/server.cpp
index 016fa78598..52b7d61f5f 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 51ae0d36db..b1ea395870 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()));