def
addresses
()
def
error
()
def
errorString
()
def
hostName
()
def
lookupId
()
def
setAddresses
(addresses)
def
setError
(error)
def
setErrorString
(errorString)
def
setHostName
(name)
def
setLookupId
(id)
def
swap
(other)
def
abortHostLookup
(lookupId)
def
fromName
(name)
def
localDomainName
()
def
localHostName
()
QHostInfofinds 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 aQHostInfo对象。To look up a host’s IP addresses asynchronously, call
lookupHost(), 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 callingabortHostLookup()with the lookup ID.范例:
# To find the IP address of qt-project.org QHostInfo.lookupHost("qt-project.org", self, SLOT("printResults(QHostInfo)")) # To find the host name for 4.2.2.1 QHostInfo.lookupHost("4.2.2.1", self, SLOT("printResults(QHostInfo)"))The slot is invoked when the results are ready. The results are stored in a
QHostInfoobject. Calladdresses()to get the list of IP addresses for the host, andhostName()to get the host name that was looked up.If the lookup failed,
error()returns the type of error that occurred.errorString()gives a human-readable description of the lookup error.若希望阻塞查找,使用
fromName()函数:info = QHostInfo.fromName("qt-project.org")
QHostInfosupports Internationalized Domain Names (IDNs) through the IDNA and Punycode standards.To retrieve the name of the local host, use the static
localHostName()函数。
QHostInfouses the mechanisms provided by the operating system to perform the lookup. As per { https://tools.ietf.org/html/rfc6724 }{RFC 6724} there is no guarantee that all IP addresses registered for a domain or host will be returned.注意
Since Qt 4.6.1
QHostInfois using multiple threads for DNS lookup instead of one dedicated DNS thread. This improves performance, but also changes the order of signal emissions when usinglookupHost()compared to previous versions of Qt.注意
Since Qt 4.6.3
QHostInfois using a small internal 60 second DNS cache for performance improvements.
QHostInfo
(
d
)
¶
QHostInfo([lookupId=-1])
- param lookupId
int- param d
Constructs an empty host info object with lookup ID
id
.
另请参阅
PySide2.QtNetwork.QHostInfo.
HostInfoError
¶
This enum describes the various errors that can occur when trying to resolve a host name.
|
常量 |
描述 |
|---|---|
|
QHostInfo.NoError |
查找成功。 |
|
QHostInfo.HostNotFound |
No IP addresses were found for the host. |
|
QHostInfo.UnknownError |
出现未知错误。 |
另请参阅
PySide2.QtNetwork.QHostInfo.
abortHostLookup
(
lookupId
)
¶
lookupId
–
int
Aborts the host lookup with the ID
id
, as returned by
lookupHost()
.
另请参阅
lookupHost()
lookupId()
PySide2.QtNetwork.QHostInfo.
addresses
(
)
¶
Returns the list of IP addresses associated with
hostName()
. This list may be empty.
范例:
info = QHostInfo()
...
if not info.addresses().isEmpty():
address = info.addresses().first()
# use the first IP address
PySide2.QtNetwork.QHostInfo.
error
(
)
¶
Returns the type of error that occurred if the host name lookup failed; otherwise returns
NoError
.
另请参阅
PySide2.QtNetwork.QHostInfo.
errorString
(
)
¶
unicode
If the lookup failed, this function returns a human readable description of the error; otherwise “Unknown error” is returned.
另请参阅
PySide2.QtNetwork.QHostInfo.
fromName
(
name
)
¶
name – unicode
Looks up the IP address(es) for the given host
name
. 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
QHostInfo
对象。
If you pass a literal IP address to
name
instead of a host name,
QHostInfo
will search for the domain name for the IP (i.e.,
QHostInfo
will perform a
reverse
lookup). On success, the returned
QHostInfo
will contain both the resolved domain name and IP addresses for the host name.
另请参阅
lookupHost()
PySide2.QtNetwork.QHostInfo.
hostName
(
)
¶
unicode
Returns the name of the host whose IP addresses were looked up.
PySide2.QtNetwork.QHostInfo.
localDomainName
(
)
¶
unicode
Returns the DNS domain of this machine.
注意
DNS domains are not related to domain names found in Windows networks.
另请参阅
PySide2.QtNetwork.QHostInfo.
localHostName
(
)
¶
unicode
Returns this machine’s host name, if one is configured. Note that hostnames are not guaranteed to be globally unique, especially if they were configured automatically.
This function does not guarantee the returned host name is a Fully Qualified Domain Name (FQDN). For that, use
fromName()
to resolve the returned name to an FQDN.
This function returns the same as
machineHostName()
.
PySide2.QtNetwork.QHostInfo.
lookupId
(
)
¶
int
Returns the ID of this lookup.
PySide2.QtNetwork.QHostInfo.
setAddresses
(
addresses
)
¶
addresses –
Sets the list of addresses in this
QHostInfo
to
addresses
.
另请参阅
PySide2.QtNetwork.QHostInfo.
setError
(
error
)
¶
error
–
HostInfoError
Sets the error type of this
QHostInfo
to
error
.
另请参阅
PySide2.QtNetwork.QHostInfo.
setErrorString
(
errorString
)
¶
errorString – unicode
Sets the human readable description of the error that occurred to
str
if the lookup failed.
另请参阅
PySide2.QtNetwork.QHostInfo.
setHostName
(
name
)
¶
name – unicode
Sets the host name of this
QHostInfo
to
hostName
.
另请参阅
PySide2.QtNetwork.QHostInfo.
setLookupId
(
id
)
¶
id
–
int
Sets the ID of this lookup to
id
.
另请参阅
lookupId()
lookupHost()