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
|
<?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">  </td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <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 <i>id</i> = -1)</li><li><div class="fn" /><b><a href="qhostinfo.html#QHostInfo-2">__init__</a></b> (<i>self</i>, QHostInfo)</li><li><div class="fn" />list-of-QHostAddress <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>, list-of-QHostAddress)</li><li><div class="fn" /><b><a href="qhostinfo.html#setError">setError</a></b> (<i>self</i>, HostInfoError)</li><li><div class="fn" /><b><a href="qhostinfo.html#setErrorString">setErrorString</a></b> (<i>self</i>, QString)</li><li><div class="fn" /><b><a href="qhostinfo.html#setHostName">setHostName</a></b> (<i>self</i>, QString)</li><li><div class="fn" /><b><a href="qhostinfo.html#setLookupId">setLookupId</a></b> (<i>self</i>, int)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" /><b><a href="qhostinfo.html#abortHostLookup">abortHostLookup</a></b> (int)</li><li><div class="fn" />QHostInfo <b><a href="qhostinfo.html#fromName">fromName</a></b> (QString)</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, QObject, SLOT(QHostInfo)SLOT())</li><li><div class="fn" />int <b><a href="qhostinfo.html#lookupHost-2">lookupHost</a></b> (QString, callable)</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><span class="comment"> // To find the IP address of qt.nokia.com</span>
QHostInfo.lookupHost("qt.nokia.com",
this, SLOT(printResults(QHostInfo)));
<span class="comment"> // To find the host name for 4.2.2.1</span>
QHostInfo.lookupHost("4.2.2.1",
this, SLOT(printResults(QHostInfo)));</pre>
<p>The slot is invoked when the results are ready. (If you use Qt for Embedded Linux and disabled multithreading 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("qt.nokia.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>
<p><table border="1" cellpadding="2" cellspacing="1" class="valuelist" 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></p>
<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 <i>id</i> = -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>)</h3><p>Constructs a copy of <i>other</i>.</p>
<a name="//apple_ref/cpp/instm/QHostInfo/~QHostInfo" />
<h3 class="fn"><a name="abortHostLookup" />QHostInfo.abortHostLookup (int)</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>
<a name="//apple_ref/cpp/instm/QHostInfo/addresses" />
<h3 class="fn"><a name="addresses" />list-of-QHostAddress 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();
<span class="comment">// use the first IP address</span>
}</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>
<a name="//apple_ref/cpp/instm/QHostInfo/error" />
<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>
<a name="//apple_ref/cpp/instm/QHostInfo/errorString" />
<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>See also <a href="qhostinfo.html#setErrorString">setErrorString</a>() and <a href="qhostinfo.html#error">error</a>().</p>
<a name="//apple_ref/cpp/clm/QHostInfo/fromName" />
<h3 class="fn"><a name="fromName" /><a href="qhostinfo.html">QHostInfo</a> QHostInfo.fromName (QString)</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>
<a name="//apple_ref/cpp/instm/QHostInfo/hostName" />
<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>See also <a href="qhostinfo.html#setHostName">setHostName</a>() and <a href="qhostinfo.html#localHostName">localHostName</a>().</p>
<a name="//apple_ref/cpp/clm/QHostInfo/localDomainName" />
<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>See also <a href="qhostinfo.html#hostName">hostName</a>().</p>
<a name="//apple_ref/cpp/clm/QHostInfo/localHostName" />
<h3 class="fn"><a name="localHostName" />QString QHostInfo.localHostName ()</h3><p>Returns the host name of this machine.</p>
<p>See also <a href="qhostinfo.html#hostName">hostName</a>().</p>
<a name="//apple_ref/cpp/clm/QHostInfo/lookupHost" />
<h3 class="fn"><a name="lookupHost" />int QHostInfo.lookupHost (QString, <a href="qobject.html">QObject</a>, SLOT(QHostInfo)SLOT())</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 &host)
{
if (host.error() != QHostInfo.NoError) {
qDebug() << "Lookup failed:" << host.errorString();
return;
}
foreach (QHostAddress address, host.addresses())
qDebug() << "Found address:" << 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><b>Note:</b> There is no guarantee on the order the signals will be emitted if you start multiple requests with lookupHost().</p>
<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>
<a name="//apple_ref/cpp/instm/QHostInfo/lookupId" />
<h3 class="fn"><a name="lookupHost-2" />int QHostInfo.lookupHost (QString, callable)</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>
<a name="//apple_ref/cpp/instm/QHostInfo/setAddresses" />
<h3 class="fn"><a name="setAddresses" />QHostInfo.setAddresses (<i>self</i>, list-of-QHostAddress)</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>
<a name="//apple_ref/cpp/instm/QHostInfo/setError" />
<h3 class="fn"><a name="setError" />QHostInfo.setError (<i>self</i>, <a href="qhostinfo.html#HostInfoError-enum">HostInfoError</a>)</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>
<a name="//apple_ref/cpp/instm/QHostInfo/setErrorString" />
<h3 class="fn"><a name="setErrorString" />QHostInfo.setErrorString (<i>self</i>, QString)</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>
<a name="//apple_ref/cpp/instm/QHostInfo/setHostName" />
<h3 class="fn"><a name="setHostName" />QHostInfo.setHostName (<i>self</i>, QString)</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>
<a name="//apple_ref/cpp/instm/QHostInfo/setLookupId" />
<h3 class="fn"><a name="setLookupId" />QHostInfo.setLookupId (<i>self</i>, int)</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>
<a name="//apple_ref/cpp/instm/QHostInfo/operator=" />
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.7.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2010</td><td align="right" width="25%">Qt 4.6.2</td></tr></table></div></address></body></html>
|