返回介绍

QHostAddress Class

发布于 2019-10-04 15:00:38 字数 4142 浏览 1304 评论 0 收藏 0

The QHostAddress class provides an IP address. More...

#include <qhostaddress.h>

List of all member functions.

Public Members

  • QHostAddress ()
  • QHostAddress ( Q_UINT32ip4Addr )
  • QHostAddress ( Q_UINT8*ip6Addr )
  • QHostAddress ( constQHostAddress&address )
  • virtual ~QHostAddress ()
  • QHostAddress & operator= ( constQHostAddress&address )
  • void setAddress ( Q_UINT32ip4Addr )
  • void setAddress ( Q_UINT8*ip6Addr )
  • bool setAddress ( constQString&address )
  • bool isIp4Addr () const
  • Q_UINT32 ip4Addr () const
  • QString toString () const
  • bool operator== ( constQHostAddress&other ) const

Detailed Description

The QHostAddress class provides an IP address.

This class contains an IP address in a platform and protocol independent manner. It stores both IPv4 and IPv6 addresses in a way that you can easily access on any platform. (Qt does not currently provide IPv6 support.)

QHostAddress is normally used with the classes QSocket, QServerSocket and QSocketDevice to set up a server or to connect to a host.

Host addresses may be set with setAddress() and retrieved with ip4Addr() or toString().

See also QSocket, QServerSocket, QSocketDevice and Input/Output and Networking.


Member Function Documentation

QHostAddress::QHostAddress ()

Creates a host address object with the IP address 0.0.0.0.

QHostAddress::QHostAddress ( Q_UINT32ip4Addr )

Creates a host address object for the IPv4 address ip4Addr.

QHostAddress::QHostAddress ( Q_UINT8*ip6Addr )

Creates a host address object with the specified IPv6 address.

ip6Addr must be a 16 byte array in network byte order (high-order byte first)

QHostAddress::QHostAddress ( constQHostAddress&address )

Creates a copy of address.

QHostAddress::~QHostAddress () [virtual]

Destroys the host address object.

Q_UINT32 QHostAddress::ip4Addr () const

Returns the IPv4 address as a number.

For example, if the address is 127.0.0.1, the returned value is 2130706433 (hex: 7f000001).

This value is only valid when isIp4Addr() returns TRUE.

See also toString().

bool QHostAddress::isIp4Addr () const

Returns TRUE if the host address represents a IPv4 address; otherwise returns FALSE.

QHostAddress& QHostAddress::operator= ( constQHostAddress&address )

Assigns another host address object address to this object and returns a reference to this object.

bool QHostAddress::operator== ( constQHostAddress&other ) const

Returns TRUE if this host address is the same as other; otherwise returns FALSE.

void QHostAddress::setAddress ( Q_UINT32ip4Addr )

Set the IPv4 address specified by ip4Addr.

void QHostAddress::setAddress ( Q_UINT8*ip6Addr )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Set the IPv6 address specified by ip6Addr.

ip6Addr must be a 16 byte array in network byte order (high-order byte first)

bool QHostAddress::setAddress ( constQString&address )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the IPv4 or IPv6 address specified by the string representation address (e.g. "127.0.0.1"). Returns TRUE and sets the address if the address was successfully parsed; otherwise returns FALSE and leaves the address unchanged.

QString QHostAddress::toString () const

Returns the address as a string.

For example, if the address is the IPv4 address 127.0.0.1, the returned string is "127.0.0.1".

See also ip4Addr().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文