summaryrefslogtreecommitdiffstats
path: root/examples/network
diff options
context:
space:
mode:
authorMarius Storm-Olsen <marius.storm-olsen@nokia.com>2009-11-13 09:34:23 (GMT)
committerMarius Storm-Olsen <marius.storm-olsen@nokia.com>2009-11-13 09:34:23 (GMT)
commitece530b88059cdfb166a99bba95ef4b70ce4ec66 (patch)
tree7af49213a328dfb6a09fbac8f27334d0737430b4 /examples/network
parent6b84baddfb5187219b76d0d9a112db27bee29d2c (diff)
parentf7a1117cbec5638e32ea04b6a93412b193e07913 (diff)
downloadQt-ece530b88059cdfb166a99bba95ef4b70ce4ec66.zip
Qt-ece530b88059cdfb166a99bba95ef4b70ce4ec66.tar.gz
Qt-ece530b88059cdfb166a99bba95ef4b70ce4ec66.tar.bz2
Merge commit 'coreteam/4.6' into oslo1-4.6
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/blockingfortuneclient/blockingclient.cpp17
-rw-r--r--examples/network/fortuneclient/client.cpp4
-rw-r--r--examples/network/fortuneserver/server.cpp4
-rw-r--r--examples/network/threadedfortuneserver/dialog.cpp4
4 files changed, 25 insertions, 4 deletions
diff --git a/examples/network/blockingfortuneclient/blockingclient.cpp b/examples/network/blockingfortuneclient/blockingclient.cpp
index b731f7a..a3d7c23 100644
--- a/examples/network/blockingfortuneclient/blockingclient.cpp
+++ b/examples/network/blockingfortuneclient/blockingclient.cpp
@@ -50,7 +50,22 @@ BlockingClient::BlockingClient(QWidget *parent)
hostLabel = new QLabel(tr("&Server name:"));
portLabel = new QLabel(tr("S&erver port:"));
- hostLineEdit = new QLineEdit("Localhost");
+ // find out which IP to connect to
+ 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();
+ break;
+ }
+ }
+ // if we did not find one, use IPv4 localhost
+ if (ipAddress.isEmpty())
+ ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
+
+ hostLineEdit = new QLineEdit(ipAddress);
portLineEdit = new QLineEdit;
portLineEdit->setValidator(new QIntValidator(1, 65535, this));
diff --git a/examples/network/fortuneclient/client.cpp b/examples/network/fortuneclient/client.cpp
index ca5d40e..e043f78 100644
--- a/examples/network/fortuneclient/client.cpp
+++ b/examples/network/fortuneclient/client.cpp
@@ -62,8 +62,10 @@ Client::Client(QWidget *parent)
// 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())
+ ipAddressesList.at(i).toIPv4Address()) {
ipAddress = ipAddressesList.at(i).toString();
+ break;
+ }
}
// if we did not find one, use IPv4 localhost
if (ipAddress.isEmpty())
diff --git a/examples/network/fortuneserver/server.cpp b/examples/network/fortuneserver/server.cpp
index 52b7d61..06f6eeb 100644
--- a/examples/network/fortuneserver/server.cpp
+++ b/examples/network/fortuneserver/server.cpp
@@ -68,8 +68,10 @@ Server::Server(QWidget *parent)
// 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())
+ ipAddressesList.at(i).toIPv4Address()) {
ipAddress = ipAddressesList.at(i).toString();
+ break;
+ }
}
// if we did not find one, use IPv4 localhost
if (ipAddress.isEmpty())
diff --git a/examples/network/threadedfortuneserver/dialog.cpp b/examples/network/threadedfortuneserver/dialog.cpp
index b1ea395..d0d3fc0 100644
--- a/examples/network/threadedfortuneserver/dialog.cpp
+++ b/examples/network/threadedfortuneserver/dialog.cpp
@@ -67,8 +67,10 @@ Dialog::Dialog(QWidget *parent)
// 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())
+ ipAddressesList.at(i).toIPv4Address()) {
ipAddress = ipAddressesList.at(i).toString();
+ break;
+ }
}
// if we did not find one, use IPv4 localhost
if (ipAddress.isEmpty())