QHostInfo
Header: #include <QHostInfo>
Public Functions
QHostInfo(int id = -1) | |
QHostInfo(const QHostInfo &other) | |
~QHostInfo() | |
QList<QHostAddress> | addresses() const |
QHostInfo::HostInfoError | error() const |
QString | errorString() const |
QString | hostName() const |
int | lookupId() const |
void | setAddresses(const QList<QHostAddress> &addresses) |
void | setError(QHostInfo::HostInfoError error) |
void | setErrorString(const QString &str) |
void | setHostName(const QString &hostName) |
void | setLookupId(int id) |
void | swap(QHostInfo &other) |
QHostInfo & | operator=(const QHostInfo &other) |
QHostInfo & | operator=(QHostInfo &&other) |
Static Public Members
void | abortHostLookup(int id) |
QHostInfo | fromName(const QString &name) |
QString | localDomainName() |
QString | localHostName() |
int | lookupHost(const QString &name, QObject *receiver, const char *member) |
int | lookupHost(const QString &name, const QObject *receiver, PointerToMemberFunction function) |
int | lookupHost(const QString &name, Functor functor) |
int | lookupHost(const QString &name, const QObject *context, Functor functor) |
Detailed Description
QHostInfo类为主机名查找提供静态函数。
QHostInfo使用操作系统提供的查找机制来查找与主机名关联的IP地址,或与IP地址关联的主机名。该类提供了两个静态方便函数:一个异步工作并在找到主机后发出信号,另一个阻止并返回QHostInfo对象。
要异步查找主机的IP地址,请调用lookupHost(),它将主机名或IP地址、接收方对象和插槽签名作为参数并返回ID。可以通过使用查找ID调用abortHostLookup()中止查找。
例子:
// To find the IP address of qt-project.org QHostInfo::lookupHost("qt-project.org", this, SLOT(printResults(QHostInfo))); // To find the host name for 4.2.2.1 QHostInfo::lookupHost("4.2.2.1", this, SLOT(printResults(QHostInfo)));
#################