aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp
blob: 1602b105be9dd7b5ff4a2cb1dcf9722372bbb33d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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]