aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp')
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp b/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp
new file mode 100644
index 000000000..1602b105b
--- /dev/null
+++ b/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp
@@ -0,0 +1,42 @@
+//! [0]
+# To find the IP address of qtsoftware.com
+QHostInfo.lookupHost("qtsoftware.com", self, SLOT("printResults(QHostInfo)"))
+
+# To find the host name for 4.2.2.1
+QHostInfo.lookupHost("4.2.2.1", self, SLOT("printResults(QHostInfo)"))
+//! [0]
+
+
+//! [1]
+info = QHostInfo.fromName("qtsoftware.com")
+//! [1]
+
+
+//! [2]
+QHostInfo.lookupHost("www.kde.org", self.lookedUp)
+//! [2]
+
+
+//! [3]
+def lookedUp(host):
+ if host.error() != QHostInfo.NoError:
+ print "Lookup failed: %s" % host.errorString()
+ return
+
+ for address in host.addresses():
+ print "Found address: %s" % address.toString()
+//! [3]
+
+
+//! [4]
+QHostInfo.lookupHost("4.2.2.1", self.lookedUp)
+//! [4]
+
+
+//! [5]
+info = QHostInfo()
+...
+if not info.addresses().isEmpty():
+ address = info.addresses().first()
+ # use the first IP address
+//! [5]