File: qhostinfo.html

package info (click to toggle)
python-qt4 4.12.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 40,300 kB
  • ctags: 6,185
  • sloc: python: 125,988; cpp: 13,291; xml: 292; makefile: 246; php: 27; sh: 2
file content (217 lines) | stat: -rw-r--r-- 18,217 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?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="index.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>id</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" />unknown-type <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>, unknown-type&#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#localDomainName">localDomainName</a></b> ()</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>, object&#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>, object&#160;<i>slot</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 class="cpp">
 <span class="comment">// To find the IP address of qt.nokia.com</span>
 <span class="type">QHostInfo</span><span class="operator">.</span><a href="qhostinfo.html#lookupHost">lookupHost</a>(<span class="string">"qt.nokia.com"</span><span class="operator">,</span>
                       <span class="keyword">this</span><span class="operator">,</span> SLOT(printResults(<span class="type">QHostInfo</span>)));

 <span class="comment">// To find the host name for 4.2.2.1</span>
 <span class="type">QHostInfo</span><span class="operator">.</span><a href="qhostinfo.html#lookupHost">lookupHost</a>(<span class="string">"4.2.2.1"</span><span class="operator">,</span>
                       <span class="keyword">this</span><span class="operator">,</span> SLOT(printResults(<span class="type">QHostInfo</span>)));
</pre>
<p>The slot is invoked when the results are ready. 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 class="cpp">
 <span class="type">QHostInfo</span> info <span class="operator">=</span> <span class="type">QHostInfo</span><span class="operator">.</span><a href="qhostinfo.html#fromName">fromName</a>(<span class="string">"qt.nokia.com"</span>);
</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><b>Note:</b> Since Qt 4.6.1 QHostInfo is using multiple threads
for DNS lookup instead of one dedicated DNS thread. This improves
performance, but also changes the order of signal emissions when
using <a href="qhostinfo.html#lookupHost">lookupHost</a>() compared
to previous versions of Qt. <b>Note:</b> Since Qt 4.6.3 QHostInfo
is using a small internal 60 second DNS cache for performance
improvements.</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 class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QHostInfo.NoError</tt></td>
<td class="topAlign"><tt>0</tt></td>
<td class="topAlign">The lookup was successful.</td>
</tr>
<tr>
<td class="topAlign"><tt>QHostInfo.HostNotFound</tt></td>
<td class="topAlign"><tt>1</tt></td>
<td class="topAlign">No IP addresses were found for the host.</td>
</tr>
<tr>
<td class="topAlign"><tt>QHostInfo.UnknownError</tt></td>
<td class="topAlign"><tt>2</tt></td>
<td class="topAlign">An unknown error occurred.</td>
</tr>
</table>
<p><b>See also</b> <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>id</i>&#160;=&#160;-1)</h3><p>Constructs an empty host info object with lookup ID
<i>id</i>.</p>
<p><b>See also</b> <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><b>See also</b> <a href="qhostinfo.html#lookupHost">lookupHost</a>() and <a href="qhostinfo.html#lookupId">lookupId</a>().</p>


<h3 class="fn"><a name="addresses" />unknown-type 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 class="cpp">
 <span class="type"><a href="qhostinfo.html">QHostInfo</a></span> info;
 <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
 <span class="keyword">if</span> (<span class="operator">!</span>info<span class="operator">.</span>addresses()<span class="operator">.</span>isEmpty()) {
     <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> address <span class="operator">=</span> info<span class="operator">.</span>addresses()<span class="operator">.</span>first();
     <span class="comment">// use the first IP address</span>
 }
</pre>
<p><b>See also</b> <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><b>See also</b> <a href="qhostinfo.html#setError">setError</a>()
and <a href="qhostinfo.html#errorString">errorString</a>().</p>


<h3 class="fn"><a name="errorString" />QString 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><b>See also</b> <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 (QString&#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><b>See also</b> <a href="qhostinfo.html#lookupHost">lookupHost</a>().</p>


<h3 class="fn"><a name="hostName" />QString QHostInfo.hostName (<i>self</i>)</h3><p>Returns the name of the host whose IP addresses were looked
up.</p>
<p><b>See also</b> <a href="qhostinfo.html#setHostName">setHostName</a>() and <a href="qhostinfo.html#localHostName">localHostName</a>().</p>


<h3 class="fn"><a name="localDomainName" />QString QHostInfo.localDomainName ()</h3><p>Returns the DNS domain of this machine.</p>
<p>Note: DNS domains are not related to domain names found in
Windows networks.</p>
<p><b>See also</b> <a href="qhostinfo.html#hostName">hostName</a>().</p>


<h3 class="fn"><a name="localHostName" />QString QHostInfo.localHostName ()</h3><p>Returns the host name of this machine.</p>
<p><b>See also</b> <a href="qhostinfo.html#hostName">hostName</a>().</p>


<h3 class="fn"><a name="lookupHost" />int QHostInfo.lookupHost (QString&#160;<i>name</i>, <a href="qobject.html">QObject</a>&#160;<i>receiver</i>, object&#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 class="cpp">
 <span class="type"><a href="qhostinfo.html">QHostInfo</a></span><span class="operator">.</span>lookupHost(<span class="string">"www.kde.org"</span><span class="operator">,</span>
                       <span class="keyword">this</span><span class="operator">,</span> SLOT(lookedUp(<span class="type"><a href="qhostinfo.html">QHostInfo</a></span>)));
</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 class="cpp">
 <span class="type">void</span> MyWidget<span class="operator">.</span>lookedUp(<span class="keyword">const</span> <span class="type"><a href="qhostinfo.html">QHostInfo</a></span> <span class="operator">&amp;</span>host)
 {
     <span class="keyword">if</span> (host<span class="operator">.</span>error() <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="qhostinfo.html">QHostInfo</a></span><span class="operator">.</span>NoError) {
         <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">"Lookup failed:"</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> host<span class="operator">.</span>errorString();
         <span class="keyword">return</span>;
     }

     foreach (<span class="keyword">const</span> <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> <span class="operator">&amp;</span>address<span class="operator">,</span> host<span class="operator">.</span>addresses())
         <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">"Found address:"</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> address<span class="operator">.</span>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 class="cpp">
 <span class="type"><a href="qhostinfo.html">QHostInfo</a></span><span class="operator">.</span>lookupHost(<span class="string">"4.2.2.1"</span><span class="operator">,</span>
                       <span class="keyword">this</span><span class="operator">,</span> SLOT(lookedUp(<span class="type"><a href="qhostinfo.html">QHostInfo</a></span>)));
</pre>
<p><b>Note:</b> There is no guarantee on the order the signals will
be emitted if you start multiple requests with lookupHost().</p>
<p><b>See also</b> <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 (QString&#160;<i>name</i>, object&#160;<i>slot</i>)</h3><h3 class="fn"><a name="lookupId" />int QHostInfo.lookupId (<i>self</i>)</h3><p>Returns the ID of this lookup.</p>
<p><b>See also</b> <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>, unknown-type&#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><b>See also</b> <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><b>See also</b> <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>, QString&#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><b>See also</b> <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>, QString&#160;<i>name</i>)</h3><p>Sets the host name of this <a href="qhostinfo.html">QHostInfo</a> to <i>hostName</i>.</p>
<p><b>See also</b> <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><b>See also</b> <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 align="left" width="25%">PyQt&#160;4.12.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.qt.io">The Qt Company</a> 2015</td><td align="right" width="25%">Qt&#160;4.8.7</td></tr></table></div></address></body></html>