1
<?xml version="1.0" encoding="iso-8859-1"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
3
<html><head><title>QHostAddress Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
4
a:link { color: #004faf; text-decoration: none }
5
a:visited { color: #672967; text-decoration: none }
6
td.postheader { font-family: sans-serif }
7
tr.address { font-family: sans-serif }
8
body { background: #ffffff; color: black; }
9
</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="index.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">QHostAddress Class Reference<br /><sup><sup>[<a href="qtnetwork.html">QtNetwork</a> module]</sup></sup></h1><p>The QHostAddress class provides an IP address. <a href="#details">More...</a></p>
11
<h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qhostaddress.html#SpecialAddress-enum">SpecialAddress</a></b> { Null, Broadcast, LocalHost, LocalHostIPv6, AnyIPv6, Any }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qhostaddress.html#QHostAddress">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qhostaddress.html#QHostAddress-2">__init__</a></b> (<i>self</i>, SpecialAddress <i>address</i>)</li><li><div class="fn" /><b><a href="qhostaddress.html#QHostAddress-3">__init__</a></b> (<i>self</i>, int <i>ip4Addr</i>)</li><li><div class="fn" /><b><a href="qhostaddress.html#QHostAddress-4">__init__</a></b> (<i>self</i>, QString <i>address</i>)</li><li><div class="fn" /><b><a href="qhostaddress.html#QHostAddress-5">__init__</a></b> (<i>self</i>, 16-tuple-of-int <i>ip6Addr</i>)</li><li><div class="fn" /><b><a href="qhostaddress.html#QHostAddress-6">__init__</a></b> (<i>self</i>, QHostAddress <i>copy</i>)</li><li><div class="fn" /><b><a href="qhostaddress.html#clear">clear</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qhostaddress.html#isInSubnet">isInSubnet</a></b> (<i>self</i>, QHostAddress <i>subnet</i>, int <i>netmask</i>)</li><li><div class="fn" />bool <b><a href="qhostaddress.html#isInSubnet-2">isInSubnet</a></b> (<i>self</i>, tuple-of-QHostAddress-int <i>subnet</i>)</li><li><div class="fn" />bool <b><a href="qhostaddress.html#isNull">isNull</a></b> (<i>self</i>)</li><li><div class="fn" />QAbstractSocket.NetworkLayerProtocol <b><a href="qhostaddress.html#protocol">protocol</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qhostaddress.html#scopeId">scopeId</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qhostaddress.html#setAddress">setAddress</a></b> (<i>self</i>, int <i>ip4Addr</i>)</li><li><div class="fn" />bool <b><a href="qhostaddress.html#setAddress-2">setAddress</a></b> (<i>self</i>, QString <i>address</i>)</li><li><div class="fn" /><b><a href="qhostaddress.html#setAddress-3">setAddress</a></b> (<i>self</i>, 16-tuple-of-int <i>ip6Addr</i>)</li><li><div class="fn" /><b><a href="qhostaddress.html#setScopeId">setScopeId</a></b> (<i>self</i>, QString <i>id</i>)</li><li><div class="fn" />int <b><a href="qhostaddress.html#toIPv4Address">toIPv4Address</a></b> (<i>self</i>)</li><li><div class="fn" />16-tuple-of-int <b><a href="qhostaddress.html#toIPv6Address">toIPv6Address</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qhostaddress.html#toString">toString</a></b> (<i>self</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />tuple-of-QHostAddress-int <b><a href="qhostaddress.html#parseSubnet">parseSubnet</a></b> (QString <i>subnet</i>)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" />bool <b><a href="qhostaddress.html#__eq__">__eq__</a></b> (<i>self</i>, QHostAddress <i>address</i>)</li><li><div class="fn" />bool <b><a href="qhostaddress.html#__eq__-2">__eq__</a></b> (<i>self</i>, SpecialAddress <i>address</i>)</li><li><div class="fn" />int <b><a href="qhostaddress.html#__hash__">__hash__</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qhostaddress.html#__ne__">__ne__</a></b> (<i>self</i>, QHostAddress <i>address</i>)</li><li><div class="fn" />bool <b><a href="qhostaddress.html#__ne__-2">__ne__</a></b> (<i>self</i>, SpecialAddress <i>address</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QHostAddress class provides an IP address.</p>
12
<p>This class holds an IPv4 or IPv6 address in a platform- and
13
protocol-independent manner.</p>
14
<p>QHostAddress is normally used with the <a href="qtcpsocket.html">QTcpSocket</a>, <a href="qtcpserver.html">QTcpServer</a>, and <a href="qudpsocket.html">QUdpSocket</a> to connect to a host or to set up
16
<p>A host address is set with <a href="qhostaddress.html#setAddress">setAddress</a>(), and retrieved with
17
<a href="qhostaddress.html#toIPv4Address">toIPv4Address</a>(),
18
<a href="qhostaddress.html#toIPv6Address">toIPv6Address</a>(), or
19
<a href="qhostaddress.html#toString">toString</a>(). You can check
20
the type with <a href="qhostaddress.html#protocol">protocol</a>().</p>
21
<p><b>Note:</b> Please note that QHostAddress does not do DNS
22
lookups. <a href="qhostinfo.html">QHostInfo</a> is needed for
24
<p>The class also supports common predefined addresses: <a href="qhostaddress.html#SpecialAddress-enum">Null</a>, <a href="qhostaddress.html#SpecialAddress-enum">LocalHost</a>, <a href="qhostaddress.html#SpecialAddress-enum">LocalHostIPv6</a>, <a href="qhostaddress.html#SpecialAddress-enum">Broadcast</a>, and <a href="qhostaddress.html#SpecialAddress-enum">Any</a>.</p>
25
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="SpecialAddress-enum" />QHostAddress.SpecialAddress</h3><table class="valuelist">
26
<tr class="odd" valign="top">
27
<th class="tblConst">Constant</th>
28
<th class="tblval">Value</th>
29
<th class="tbldscr">Description</th>
32
<td class="topAlign"><tt>QHostAddress.Null</tt></td>
33
<td class="topAlign"><tt>0</tt></td>
34
<td class="topAlign">The null address object. Equivalent to
35
<a href="qhostaddress.html#QHostAddress">QHostAddress</a>().</td>
38
<td class="topAlign"><tt>QHostAddress.LocalHost</tt></td>
39
<td class="topAlign"><tt>2</tt></td>
40
<td class="topAlign">The IPv4 localhost address. Equivalent to
41
<a href="qhostaddress.html">QHostAddress</a>("127.0.0.1").</td>
44
<td class="topAlign"><tt>QHostAddress.LocalHostIPv6</tt></td>
45
<td class="topAlign"><tt>3</tt></td>
46
<td class="topAlign">The IPv6 localhost address. Equivalent to
47
<a href="qhostaddress.html">QHostAddress</a>(".1").</td>
50
<td class="topAlign"><tt>QHostAddress.Broadcast</tt></td>
51
<td class="topAlign"><tt>1</tt></td>
52
<td class="topAlign">The IPv4 broadcast address. Equivalent to
53
<a href="qhostaddress.html">QHostAddress</a>("255.255.255.255").</td>
56
<td class="topAlign"><tt>QHostAddress.Any</tt></td>
57
<td class="topAlign"><tt>4</tt></td>
58
<td class="topAlign">The IPv4 any-address. Equivalent to <a href="qhostaddress.html">QHostAddress</a>("0.0.0.0").</td>
61
<td class="topAlign"><tt>QHostAddress.AnyIPv6</tt></td>
62
<td class="topAlign"><tt>5</tt></td>
63
<td class="topAlign">The IPv6 any-address. Equivalent to <a href="qhostaddress.html">QHostAddress</a>("<a href="index.html">.</a>").</td>
66
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QHostAddress" />QHostAddress.__init__ (<i>self</i>)</h3><p>Constructs a host address object with the IP address
68
<p><b>See also</b> <a href="qhostaddress.html#clear">clear</a>().</p>
71
<h3 class="fn"><a name="QHostAddress-2" />QHostAddress.__init__ (<i>self</i>, <a href="qhostaddress.html#SpecialAddress-enum">SpecialAddress</a> <i>address</i>)</h3><p>Constructs a host address object with the IPv4 address
75
<h3 class="fn"><a name="QHostAddress-3" />QHostAddress.__init__ (<i>self</i>, int <i>ip4Addr</i>)</h3><p>Constructs a host address object with the IPv6 address
77
<p><i>ip6Addr</i> must be a 16-byte array in network byte order
81
<h3 class="fn"><a name="QHostAddress-4" />QHostAddress.__init__ (<i>self</i>, QString <i>address</i>)</h3><p>Constructs a host address object with the IPv6 address
85
<h3 class="fn"><a name="QHostAddress-5" />QHostAddress.__init__ (<i>self</i>, 16-tuple-of-int <i>ip6Addr</i>)</h3><p>Constructs an IPv4 or IPv6 address using the address specified
86
by the native structure <i>sockaddr</i>.</p>
87
<p><b>See also</b> <a href="qhostaddress.html#setAddress">setAddress</a>().</p>
90
<h3 class="fn"><a name="QHostAddress-6" />QHostAddress.__init__ (<i>self</i>, <a href="qhostaddress.html">QHostAddress</a> <i>copy</i>)</h3><p>Constructs an IPv4 or IPv6 address based on the string
91
<i>address</i> (e.g., "127.0.0.1").</p>
92
<p><b>See also</b> <a href="qhostaddress.html#setAddress">setAddress</a>().</p>
95
<h3 class="fn"><a name="clear" />QHostAddress.clear (<i>self</i>)</h3><p>Sets the host address to 0.0.0.0.</p>
98
<h3 class="fn"><a name="isInSubnet" />bool QHostAddress.isInSubnet (<i>self</i>, <a href="qhostaddress.html">QHostAddress</a> <i>subnet</i>, int <i>netmask</i>)</h3><p>Returns true if this IP is in the subnet described by the
99
network prefix <i>subnet</i> and netmask <i>netmask</i>.</p>
100
<p>An IP is considered to belong to a subnet if it is contained
101
between the lowest and the highest address in that subnet. In the
102
case of IP version 4, the lowest address is the network address,
103
while the highest address is the broadcast address.</p>
104
<p>The <i>subnet</i> argument does not have to be the actual
105
network address (the lowest address in the subnet). It can be any
106
valid IP belonging to that subnet. In particular, if it is equal to
107
the IP address held by this object, this function will always
108
return true (provided the netmask is a valid value).</p>
109
<p>This function was introduced in Qt 4.5.</p>
110
<p><b>See also</b> <a href="qhostaddress.html#parseSubnet">parseSubnet</a>().</p>
113
<h3 class="fn"><a name="isInSubnet-2" />bool QHostAddress.isInSubnet (<i>self</i>, tuple-of-QHostAddress-int <i>subnet</i>)</h3><p>This is an overloaded function.</p>
114
<p>Returns true if this IP is in the subnet described by
115
<i>subnet</i>. The <a href="qhostaddress.html">QHostAddress</a>
116
member of <i>subnet</i> contains the network prefix and the int
117
(second) member contains the netmask (prefix length).</p>
118
<p>This function was introduced in Qt 4.5.</p>
121
<h3 class="fn"><a name="isNull" />bool QHostAddress.isNull (<i>self</i>)</h3><p>Returns true if this host address is null (INADDR_ANY or
122
in6addr_any). The default constructor creates a null address, and
123
that address is not valid for any host or interface.</p>
126
<h3 class="fn"><a name="parseSubnet" />tuple-of-QHostAddress-int QHostAddress.parseSubnet (QString <i>subnet</i>)</h3><p>Parses the IP and subnet information contained in <i>subnet</i>
127
and returns the network prefix for that network and its prefix
129
<p>The IP address and the netmask must be separated by a slash
131
<p>This function supports arguments in the form:</p>
133
<li>123.123.123.123/n where n is any value between 0 and 32</li>
134
<li>123.123.123.123/255.255.255.255</li>
135
<li><ipv6-address>/n where n is any value between 0 and
138
<p>For IP version 4, this function accepts as well missing trailing
139
components (i.e., less than 4 octets, like "192.168.1"), followed
140
or not by a dot. If the netmask is also missing in that case, it is
141
set to the number of octets actually passed (in the example above,
142
it would be 24, for 3 octets).</p>
143
<p>This function was introduced in Qt 4.5.</p>
144
<p><b>See also</b> <a href="qhostaddress.html#isInSubnet">isInSubnet</a>().</p>
147
<h3 class="fn"><a name="protocol" /><a href="qabstractsocket.html#NetworkLayerProtocol-enum">QAbstractSocket.NetworkLayerProtocol</a> QHostAddress.protocol (<i>self</i>)</h3><p>Returns the network layer protocol of the host address.</p>
150
<h3 class="fn"><a name="scopeId" />QString QHostAddress.scopeId (<i>self</i>)</h3><p>Returns the scope ID of an IPv6 address. For IPv4 addresses, or
151
if the address does not contain a scope ID, an empty <a href="qstring.html">QString</a> is returned.</p>
152
<p>The IPv6 scope ID specifies the scope of <i>reachability</i> for
153
non-global IPv6 addresses, limiting the area in which the address
154
can be used. All IPv6 addresses are associated with such a
155
reachability scope. The scope ID is used to disambiguate addresses
156
that are not guaranteed to be globally unique.</p>
157
<p>IPv6 specifies the following four levels of reachability:</p>
159
<li>Node-local: Addresses that are only used for communicating with
160
services on the same interface (e.g., the loopback interface
162
<li>Link-local: Addresses that are local to the network interface
163
(<i>link</i>). There is always one link-local address for each IPv6
164
interface on your host. Link-local addresses ("fe80...") are
165
generated from the MAC address of the local network adaptor, and
166
are not guaranteed to be unique.</li>
167
<li>Site-local: Addresses that are local to the site / private
168
network (e.g., the company intranet). Site-local addresses
169
("fec0...") are usually distributed by the site router, and are not
170
guaranteed to be unique outside of the local site.</li>
171
<li>Global: For globally routable addresses, such as public servers
172
on the Internet.</li>
174
<p>When using a link-local or site-local address for IPv6
175
connections, you must specify the scope ID. The scope ID for a
176
link-local address is usually the same as the interface name (e.g.,
177
"eth0", "en1") or number (e.g., "1", "2").</p>
178
<p>This function was introduced in Qt 4.1.</p>
179
<p><b>See also</b> <a href="qhostaddress.html#setScopeId">setScopeId</a>().</p>
182
<h3 class="fn"><a name="setAddress" />QHostAddress.setAddress (<i>self</i>, int <i>ip4Addr</i>)</h3><p>Set the IPv4 address specified by <i>ip4Addr</i>.</p>
185
<h3 class="fn"><a name="setAddress-2" />bool QHostAddress.setAddress (<i>self</i>, QString <i>address</i>)</h3><p>This is an overloaded function.</p>
186
<p>Set the IPv6 address specified by <i>ip6Addr</i>.</p>
187
<p><i>ip6Addr</i> must be an array of 16 bytes in network byte
188
order (high-order byte first).</p>
191
<h3 class="fn"><a name="setAddress-3" />QHostAddress.setAddress (<i>self</i>, 16-tuple-of-int <i>ip6Addr</i>)</h3><p>This is an overloaded function.</p>
192
<p>Set the IPv6 address specified by <i>ip6Addr</i>.</p>
195
<h3 class="fn"><a name="setScopeId" />QHostAddress.setScopeId (<i>self</i>, QString <i>id</i>)</h3><p>Sets the IPv6 scope ID of the address to <i>id</i>. If the
196
address protocol is not IPv6, this function does nothing.</p>
197
<p>This function was introduced in Qt 4.1.</p>
198
<p><b>See also</b> <a href="qhostaddress.html#scopeId">scopeId</a>().</p>
201
<h3 class="fn"><a name="toIPv4Address" />int QHostAddress.toIPv4Address (<i>self</i>)</h3><p>Returns the IPv4 address as a number.</p>
202
<p>For example, if the address is 127.0.0.1, the returned value is
203
2130706433 (i.e. 0x7f000001).</p>
204
<p>This value is only valid if the Protocol() is <a href="qabstractsocket.html#NetworkLayerProtocol-enum">IPv4Protocol</a>.</p>
205
<p><b>See also</b> <a href="qhostaddress.html#toString">toString</a>().</p>
208
<h3 class="fn"><a name="toIPv6Address" />16-tuple-of-int QHostAddress.toIPv6Address (<i>self</i>)</h3><p>Returns the IPv6 address as a Q_IPV6ADDR structure. The
209
structure consists of 16 unsigned characters.</p>
211
Q_IPV6ADDR addr <span class="operator">=</span> hostAddr<span class="operator">.</span>toIPv6Address();
212
<span class="comment">// addr contains 16 unsigned characters</span>
214
<span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator"><</span> <span class="number">16</span>; <span class="operator">+</span><span class="operator">+</span>i) {
215
<span class="comment">// process addr[i]</span>
218
<p>This value is only valid if the <a href="qhostaddress.html#protocol">protocol</a>() is <a href="qabstractsocket.html#NetworkLayerProtocol-enum">IPv6Protocol</a>.</p>
219
<p><b>See also</b> <a href="qhostaddress.html#toString">toString</a>().</p>
222
<h3 class="fn"><a name="toString" />QString QHostAddress.toString (<i>self</i>)</h3><p>Returns the address as a string.</p>
223
<p>For example, if the address is the IPv4 address 127.0.0.1, the
224
returned string is "127.0.0.1". For IPv6 the string format will
225
follow the RFC5952 recommendation.</p>
226
<p><b>See also</b> <a href="qhostaddress.html#toIPv4Address">toIPv4Address</a>().</p>
229
<h3 class="fn"><a name="__eq__" />bool QHostAddress.__eq__ (<i>self</i>, <a href="qhostaddress.html">QHostAddress</a> <i>address</i>)</h3><h3 class="fn"><a name="__eq__-2" />bool QHostAddress.__eq__ (<i>self</i>, <a href="qhostaddress.html#SpecialAddress-enum">SpecialAddress</a> <i>address</i>)</h3><h3 class="fn"><a name="__hash__" />int QHostAddress.__hash__ (<i>self</i>)</h3><h3 class="fn"><a name="__ne__" />bool QHostAddress.__ne__ (<i>self</i>, <a href="qhostaddress.html">QHostAddress</a> <i>address</i>)</h3><h3 class="fn"><a name="__ne__-2" />bool QHostAddress.__ne__ (<i>self</i>, <a href="qhostaddress.html#SpecialAddress-enum">SpecialAddress</a> <i>address</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.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> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>
b'\\ No newline at end of file'