File: qhostinfo.html

package info (click to toggle)
python-qt4 4.0.1-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,632 kB
  • ctags: 2,639
  • sloc: python: 29,409; sh: 5,646; cpp: 3,168; xml: 149; makefile: 109
file content (122 lines) | stat: -rw-r--r-- 15,099 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QHostInfo Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QHostInfo Class Reference<br /><sup><sup>[<a href="qtnetwork.html">QtNetwork</a> module]</sup></sup></h1><p>The QHostInfo class provides static functions for host name lookups. <a href="#details">More...</a></p>
<h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qhostinfo.html#HostInfoError-enum">HostInfoError</a></b> { NoError, HostNotFound, UnknownError }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qhostinfo.html#QHostInfo">__init__</a></b> (<i>self</i>, int&#160;<i>lookupId</i>&#160;=&#160;-1)</li><li><div class="fn" /><b><a href="qhostinfo.html#QHostInfo-2">__init__</a></b> (<i>self</i>, QHostInfo&#160;<i>d</i>)</li><li><div class="fn" />QHostAddress-list <b><a href="qhostinfo.html#addresses">addresses</a></b> (<i>self</i>)</li><li><div class="fn" />HostInfoError <b><a href="qhostinfo.html#error">error</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qhostinfo.html#errorString">errorString</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qhostinfo.html#hostName">hostName</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qhostinfo.html#lookupId">lookupId</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qhostinfo.html#setAddresses">setAddresses</a></b> (<i>self</i>, QHostAddress-list&#160;<i>addresses</i>)</li><li><div class="fn" /><b><a href="qhostinfo.html#setError">setError</a></b> (<i>self</i>, HostInfoError&#160;<i>error</i>)</li><li><div class="fn" /><b><a href="qhostinfo.html#setErrorString">setErrorString</a></b> (<i>self</i>, QString&#160;<i>errorString</i>)</li><li><div class="fn" /><b><a href="qhostinfo.html#setHostName">setHostName</a></b> (<i>self</i>, QString&#160;<i>name</i>)</li><li><div class="fn" /><b><a href="qhostinfo.html#setLookupId">setLookupId</a></b> (<i>self</i>, int&#160;<i>id</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" /><b><a href="qhostinfo.html#abortHostLookup">abortHostLookup</a></b> (int&#160;<i>lookupId</i>)</li><li><div class="fn" />QHostInfo <b><a href="qhostinfo.html#fromName">fromName</a></b> (QString&#160;<i>name</i>)</li><li><div class="fn" />QString <b><a href="qhostinfo.html#localHostName">localHostName</a></b> ()</li><li><div class="fn" />int <b><a href="qhostinfo.html#lookupHost">lookupHost</a></b> (QString&#160;<i>name</i>, QObject&#160;<i>receiver</i>, SLOT(QHostInfo)&#160;<i>member</i>)</li><li><div class="fn" />int <b><a href="qhostinfo.html#lookupHost-2">lookupHost</a></b> (QString&#160;<i>name</i>, callable&#160;<i>receiver</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QHostInfo class provides static functions for host name lookups.</p>
<p>QHostInfo uses the lookup mechanisms provided by the operating system to find the IP address(es) associated with a host name, or the host name associated with an IP address. The class provides two static convenience functions: one that works asynchronously and emits a signal once the host is found, and one that blocks and returns a QHostInfo object.</p>
<p>To look up a host's IP addresses asynchronously, call <a href="qhostinfo.html#lookupHost">lookupHost</a>(), which takes the host name or IP address, a receiver object, and a slot signature as arguments and returns an ID. You can abort the lookup by calling <a href="qhostinfo.html#abortHostLookup">abortHostLookup</a>() with the lookup ID.</p>
<p>Example:</p>
<pre>
    // To find the IP address of www.trolltech.com
    QHostInfo.lookupHost("www.trolltech.com",
                          this, SLOT(printResults(QHostInfo)));

    // To find the host name for 4.2.2.1
    QHostInfo.lookupHost("4.2.2.1",
                          this, SLOT(printResults(QHostInfo)));
</pre>
<p>The slot is invoked when the results are ready. (If you use Qtopia Core and disabled multithread support by defining <tt>QT_NO_THREAD</tt>, <a href="qhostinfo.html#lookupHost">lookupHost</a>() will block until the lookup has finished.) The results are stored in a QHostInfo object. Call <a href="qhostinfo.html#addresses">addresses</a>() to get the list of IP addresses for the host, and <a href="qhostinfo.html#hostName">hostName</a>() to get the host name that was looked up.</p>
<p>If the lookup failed, <a href="qhostinfo.html#error">error</a>() returns the type of error that occurred. <a href="qhostinfo.html#errorString">errorString</a>() gives a human-readable description of the lookup error.</p>
<p>If you want a blocking lookup, use the <a href="qhostinfo.html#fromName">QHostInfo.fromName</a>() function:</p>
<pre>
    QHostInfo info = QHostInfo.fromName("www.trolltech.com");
</pre>
<p>QHostInfo supports Internationalized Domain Names (IDNs) through the IDNA and Punycode standards.</p>
<p>To retrieve the name of the local host, use the static <a href="qhostinfo.html#localHostName">QHostInfo.localHostName</a>() function.</p>
<p>See also <a href="qabstractsocket.html">QAbstractSocket</a> and <a href="http://www.rfc-editor.org/rfc/rfc3492.txt">RFC 3492</a>.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="HostInfoError-enum" />QHostInfo.HostInfoError</h3><p>This enum describes the various errors that can occur when trying to resolve a host name.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QHostInfo.NoError</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">The lookup was successful.</td>
</tr>
<tr>
<td valign="top"><tt>QHostInfo.HostNotFound</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">No IP addresses were found for the host.</td>
</tr>
<tr>
<td valign="top"><tt>QHostInfo.UnknownError</tt></td>
<td align="center" valign="top"><tt>2</tt></td>
<td valign="top">An unknown error occurred.</td>
</tr>
</table>
<br />
<br />
<p>See also <a href="qhostinfo.html#error">error</a>() and <a href="qhostinfo.html#setError">setError</a>().</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QHostInfo" />QHostInfo.__init__ (<i>self</i>, int&#160;<i>lookupId</i>&#160;=&#160;-1)</h3><p>Constructs an empty host info object with lookup ID <i>id</i>.</p>
<p>See also <a href="qhostinfo.html#lookupId">lookupId</a>().</p>
<h3 class="fn"><a name="QHostInfo-2" />QHostInfo.__init__ (<i>self</i>, <a href="qhostinfo.html">QHostInfo</a>&#160;<i>d</i>)</h3><p>Constructs a copy of <i>other</i>.</p>
<h3 class="fn"><a name="abortHostLookup" />QHostInfo.abortHostLookup (int&#160;<i>lookupId</i>)</h3><p>Aborts the host lookup with the ID <i>id</i>, as returned by <a href="qhostinfo.html#lookupHost">lookupHost</a>().</p>
<p>See also <a href="qhostinfo.html#lookupHost">lookupHost</a>() and <a href="qhostinfo.html#lookupId">lookupId</a>().</p>
<h3 class="fn"><a name="addresses" />QHostAddress-list QHostInfo.addresses (<i>self</i>)</h3><p>Returns the list of IP addresses associated with <a href="qhostinfo.html#hostName">hostName</a>(). This list may be empty.</p>
<p>Example:</p>
<pre>
    QHostInfo info;
    ...
    if (!info.addresses.isEmpty()) {
        QHostAddress address = info.addresses().first();
        // use the first IP address
    }
</pre>
<p>See also <a href="qhostinfo.html#setAddresses">setAddresses</a>(), <a href="qhostinfo.html#hostName">hostName</a>(), and <a href="qhostinfo.html#error">error</a>().</p>
<h3 class="fn"><a name="error" /><a href="qhostinfo.html#HostInfoError-enum">HostInfoError</a> QHostInfo.error (<i>self</i>)</h3><p>Returns the type of error that occurred if the host name lookup failed; otherwise returns <a href="qhostinfo.html#HostInfoError-enum">NoError</a>.</p>
<p>See also <a href="qhostinfo.html#setError">setError</a>() and <a href="qhostinfo.html#errorString">errorString</a>().</p>
<h3 class="fn"><a name="errorString" /><a href="qstring.html">QString</a> QHostInfo.errorString (<i>self</i>)</h3><p>If the lookup failed, this function returns a human readable description of the error; otherwise "Unknown error" is returned.</p>
<p>See also <a href="qhostinfo.html#setErrorString">setErrorString</a>() and <a href="qhostinfo.html#error">error</a>().</p>
<h3 class="fn"><a name="fromName" /><a href="qhostinfo.html">QHostInfo</a> QHostInfo.fromName (<a href="qstring.html">QString</a>&#160;<i>name</i>)</h3><p>Looks up the IP address(es) for the given host <i>name</i>. The function blocks during the lookup which means that execution of the program is suspended until the results of the lookup are ready. Returns the result of the lookup in a <a href="qhostinfo.html">QHostInfo</a> object.</p>
<p>If you pass a literal IP address to <i>name</i> instead of a host name, <a href="qhostinfo.html">QHostInfo</a> will search for the domain name for the IP (i.e., <a href="qhostinfo.html">QHostInfo</a> will perform a <i>reverse</i> lookup). On success, the returned <a href="qhostinfo.html">QHostInfo</a> will contain both the resolved domain name and IP addresses for the host name.</p>
<p>See also <a href="qhostinfo.html#lookupHost">lookupHost</a>().</p>
<h3 class="fn"><a name="hostName" /><a href="qstring.html">QString</a> QHostInfo.hostName (<i>self</i>)</h3><p>Returns the name of the host whose IP addresses were looked up.</p>
<p>See also <a href="qhostinfo.html#setHostName">setHostName</a>() and <a href="qhostinfo.html#localHostName">localHostName</a>().</p>
<h3 class="fn"><a name="localHostName" /><a href="qstring.html">QString</a> QHostInfo.localHostName ()</h3><p>Returns the host name of this machine.</p>
<p>See also <a href="qhostinfo.html#hostName">hostName</a>().</p>
<h3 class="fn"><a name="lookupHost" />int QHostInfo.lookupHost (<a href="qstring.html">QString</a>&#160;<i>name</i>, <a href="qobject.html">QObject</a>&#160;<i>receiver</i>, SLOT(QHostInfo)&#160;<i>member</i>)</h3><p>Looks up the IP address(es) associated with host name <i>name</i>, and returns an ID for the lookup. When the result of the lookup is ready, the slot or signal <i>member</i> in <i>receiver</i> is called with a <a href="qhostinfo.html">QHostInfo</a> argument. The <a href="qhostinfo.html">QHostInfo</a> object can then be inspected to get the results of the lookup.</p>
<p>The lookup is performed by a single function call, for example:</p>
<pre>
    QHostInfo.lookupHost("www.kde.org",
                          this, SLOT(lookedUp(QHostInfo)));
</pre>
<p>The implementation of the slot prints basic information about the addresses returned by the lookup, or reports an error if it failed:</p>
<pre>
    void MyWidget.lookedUp(const QHostInfo &amp;host)
    {
        if (host.error() != QHostInfo.NoError) {
            qDebug() &lt;&lt; "Lookup failed:" &lt;&lt; host.errorString();
            return;
        }

        foreach (QHostAddress address, host.addresses())
            qDebug() &lt;&lt; "Found address:" &lt;&lt; address.toString();
    }
</pre>
<p>If you pass a literal IP address to <i>name</i> instead of a host name, <a href="qhostinfo.html">QHostInfo</a> will search for the domain name for the IP (i.e., <a href="qhostinfo.html">QHostInfo</a> will perform a <i>reverse</i> lookup). On success, the resulting <a href="qhostinfo.html">QHostInfo</a> will contain both the resolved domain name and IP addresses for the host name. Example:</p>
<pre>
    QHostInfo.lookupHost("4.2.2.1",
                          this, SLOT(lookedUp(QHostInfo)));
</pre>
<p>See also <a href="qhostinfo.html#abortHostLookup">abortHostLookup</a>(), <a href="qhostinfo.html#addresses">addresses</a>(), <a href="qhostinfo.html#error">error</a>(), and <a href="qhostinfo.html#fromName">fromName</a>().</p>
<h3 class="fn"><a name="lookupHost-2" />int QHostInfo.lookupHost (<a href="qstring.html">QString</a>&#160;<i>name</i>, callable&#160;<i>receiver</i>)</h3><h3 class="fn"><a name="lookupId" />int QHostInfo.lookupId (<i>self</i>)</h3><p>Returns the ID of this lookup.</p>
<p>See also <a href="qhostinfo.html#setLookupId">setLookupId</a>(), <a href="qhostinfo.html#abortHostLookup">abortHostLookup</a>(), and <a href="qhostinfo.html#hostName">hostName</a>().</p>
<h3 class="fn"><a name="setAddresses" />QHostInfo.setAddresses (<i>self</i>, QHostAddress-list&#160;<i>addresses</i>)</h3><p>Sets the list of addresses in this <a href="qhostinfo.html">QHostInfo</a> to <i>addresses</i>.</p>
<p>See also <a href="qhostinfo.html#addresses">addresses</a>().</p>
<h3 class="fn"><a name="setError" />QHostInfo.setError (<i>self</i>, <a href="qhostinfo.html#HostInfoError-enum">HostInfoError</a>&#160;<i>error</i>)</h3><p>Sets the error type of this <a href="qhostinfo.html">QHostInfo</a> to <i>error</i>.</p>
<p>See also <a href="qhostinfo.html#error">error</a>() and <a href="qhostinfo.html#errorString">errorString</a>().</p>
<h3 class="fn"><a name="setErrorString" />QHostInfo.setErrorString (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>errorString</i>)</h3><p>Sets the human readable description of the error that occurred to <i>str</i> if the lookup failed.</p>
<p>See also <a href="qhostinfo.html#errorString">errorString</a>() and <a href="qhostinfo.html#setError">setError</a>().</p>
<h3 class="fn"><a name="setHostName" />QHostInfo.setHostName (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>name</i>)</h3><p>Sets the host name of this <a href="qhostinfo.html">QHostInfo</a> to <i>hostName</i>.</p>
<p>See also <a href="qhostinfo.html#hostName">hostName</a>().</p>
<h3 class="fn"><a name="setLookupId" />QHostInfo.setLookupId (<i>self</i>, int&#160;<i>id</i>)</h3><p>Sets the ID of this lookup to <i>id</i>.</p>
<p>See also <a href="qhostinfo.html#lookupId">lookupId</a>() and <a href="qhostinfo.html#lookupHost">lookupHost</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt&#160;4.0.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.trolltech.com">Trolltech&#160;AS</a> 2006</td><td align="right" width="25%">Qt&#160;4.1.4</td></tr></table></div></address></body></html>