QDnsLookup class represents a DNS lookup. 更多...
头: | #include <QDnsLookup> |
qmake: | QT += network |
Since: | Qt 5.0 |
继承: | QObject |
enum | Error { NoError, ResolverError, OperationCancelledError, InvalidRequestError, ..., NotFoundError } |
enum | Type { A, AAAA, ANY, CNAME, ..., TXT } |
|
|
QDnsLookup (QObject * parent = Q_NULLPTR) | |
QDnsLookup (Type type , const QString & name , QObject * parent = Q_NULLPTR) | |
QDnsLookup (Type type , const QString & name , const QHostAddress & nameserver , QObject * parent = Q_NULLPTR) | |
~QDnsLookup () | |
QList<QDnsDomainNameRecord> | canonicalNameRecords () const |
Error | error () const |
QString | errorString () const |
QList<QDnsHostAddressRecord> | hostAddressRecords () const |
bool | isFinished () const |
QList<QDnsMailExchangeRecord> | mailExchangeRecords () const |
QString | name () const |
QList<QDnsDomainNameRecord> | nameServerRecords () const |
QHostAddress | nameserver () const |
QList<QDnsDomainNameRecord> | pointerRecords () const |
QList<QDnsServiceRecord> | serviceRecords () const |
void | setName (const QString & name ) |
void | setNameserver (const QHostAddress & nameserver ) |
void | setType ( QDnsLookup::Type ) |
QList<QDnsTextRecord> | textRecords () const |
类型 | type () const |
void | abort () |
void | lookup () |
void | finished () |
void | nameChanged (const QString & name ) |
void | nameserverChanged (const QHostAddress & nameserver ) |
void | typeChanged (Type type ) |
QDnsLookup class represents a DNS lookup.
QDnsLookup uses the mechanisms provided by the operating system to perform DNS lookups. To perform a lookup you need to specify a name and type 然后援引 lookup() 槽。 finished() 信号会被发射当完成时。
例如,可以确定给定域的 XMPP 聊天客户端应该连接到哪些服务器采用:
void MyObject::lookupServers() { // Create a DNS lookup. dns = new QDnsLookup(this); connect(dns, SIGNAL(finished()), this, SLOT(handleServers())); // Find the XMPP servers for gmail.com dns->setType(QDnsLookup::SRV); dns->setName("_xmpp-client._tcp.gmail.com"); dns->lookup(); }
一旦请求完成,可以处理结果采用:
void MyObject::handleServers() { // Check the lookup succeeded. if (dns->error() != QDnsLookup::NoError) { qWarning("DNS lookup failed"); dns->deleteLater(); return; } // Handle the results. const auto records = dns->serviceRecords(); for (const QDnsServiceRecord &record : records) { ... } dns->deleteLater(); }
注意: 若仅仅希望查找与主机名关联的 IP 地址 (或与 IP 地址关联的主机名),应该使用 QHostInfo 代替。
指示在 DNS 查找处理过程中发现的所有可能的错误条件。
常量 | 值 | 描述 |
---|---|---|
QDnsLookup::NoError
|
0
|
没有错误条件。 |
QDnsLookup::ResolverError
|
1
|
初始化系统的 DNS 解析器时出错。 |
QDnsLookup::OperationCancelledError
|
2
|
查找被中止使用 abort () 方法。 |
QDnsLookup::InvalidRequestError
|
3
|
请求的 DNS 查找无效。 |
QDnsLookup::InvalidReplyError
|
4
|
由服务器返回的回复无效。 |
QDnsLookup::ServerFailureError
|
5
|
服务器遭遇内部故障当处理请求时 (SERVFAIL)。 |
QDnsLookup::ServerRefusedError
|
6
|
服务器出于安全或策略原因拒绝处理请求 (REFUSED)。 |
QDnsLookup::NotFoundError
|
7
|
请求的域名不存在 (NXDOMAIN)。 |
指示所履行的 DNS 查找类型。
常量 | 值 | 描述 |
---|---|---|
QDnsLookup::A
|
1
|
IPv4 地址记录。 |
QDnsLookup::AAAA
|
28
|
IPv6 地址记录。 |
QDnsLookup::ANY
|
255
|
任何记录。 |
QDnsLookup::CNAME
|
5
|
典型名称记录。 |
QDnsLookup::MX
|
15
|
邮件交换记录。 |
QDnsLookup::NS
|
2
|
名称服务器记录。 |
QDnsLookup::PTR
|
12
|
指针记录。 |
QDnsLookup::SRV
|
33
|
服务记录。 |
QDnsLookup::TXT
|
16
|
文本记录。 |
This property holds the type of error that occurred if the DNS lookup failed, or NoError .
访问函数:
Error | error () const |
通知程序信号:
void | finished () |
This property holds a human-readable description of the error if the DNS lookup failed.
访问函数:
QString | errorString () const |
通知程序信号:
void | finished () |
此特性保持要查找的名称。
注意: The name will be encoded using IDNA, which means it's unsuitable for querying SRV records compatible with the DNS-SD specification.
访问函数:
QString | name () const |
void | setName (const QString & name ) |
通知程序信号:
void | nameChanged (const QString & name ) |
此特性保持用于 DNS 查找的名称服务器。
访问函数:
QHostAddress | nameserver () const |
void | setNameserver (const QHostAddress & nameserver ) |
通知程序信号:
void | nameserverChanged (const QHostAddress & nameserver ) |
This property holds the type of DNS lookup.
访问函数:
类型 | type () const |
void | setType ( QDnsLookup::Type ) |
通知程序信号:
void | typeChanged (Type type ) |
构造 QDnsLookup object and sets parent 作为父级对象。
type property will default to QDnsLookup::A .
构造 QDnsLookup object for the given type and name and sets parent 作为父级对象。
构造 QDnsLookup object for the given type , name and nameserver and sets parent 作为父级对象。
该函数在 Qt 5.4 引入。
销毁 QDnsLookup 对象。
It is safe to delete a QDnsLookup object even if it is not finished, you will simply never receive its results.
[slot]
void
QDnsLookup::
abort
()
中止 DNS 查找操作。
若查找已完成,什么都不做。
Returns the list of canonical name records associated with this lookup.
[signal]
void
QDnsLookup::
finished
()
此信号被发射,当回复已处理完成。
注意: 通知程序信号对于特性 error . Notifier signal for property errorString .
Returns the list of host address records associated with this lookup.
返回回复是已完成还是被中止。
[slot]
void
QDnsLookup::
lookup
()
履行 DNS 查找。
finished() signal is emitted upon completion.
Returns the list of mail exchange records associated with this lookup.
The records are sorted according to RFC 5321 , so if you use them to connect to servers, you should try them in the order they are listed.
[signal]
void
QDnsLookup::
nameChanged
(const
QString
&
name
)
此信号被发射当查找 name 改变。 name is the new lookup name.
注意: 通知程序信号对于特性 name .
Returns the list of name server records associated with this lookup.
Returns the list of pointer records associated with this lookup.
Returns the list of service records associated with this lookup.
The records are sorted according to RFC 2782 , so if you use them to connect to servers, you should try them in the order they are listed.
Returns the list of text records associated with this lookup.
[signal]
void
QDnsLookup::
typeChanged
(
Type
type
)
此信号被发射当查找 type 改变。 type 是新的查找类型。
注意: 通知程序信号对于特性 type .