![]() |
Qt 6.x
The Qt SDK
|
The QDnsLookup class represents a DNS lookup. More...
#include <qdnslookup.h>
Public Types | |
enum | Error { NoError = 0 , ResolverError , OperationCancelledError , InvalidRequestError , InvalidReplyError , ServerFailureError , ServerRefusedError , NotFoundError , TimeoutError } |
Indicates all possible error conditions found during the processing of the DNS lookup. More... | |
enum | Type { A = 1 , AAAA = 28 , ANY = 255 , CNAME = 5 , MX = 15 , NS = 2 , PTR = 12 , SRV = 33 , TXT = 16 } |
Indicates the type of DNS lookup that was performed. More... | |
Public Slots | |
void | abort () |
Aborts the DNS lookup operation. | |
void | lookup () |
Performs the DNS lookup. | |
![]() | |
void | deleteLater () |
\threadsafe | |
Signals | |
void | finished () |
This signal is emitted when the reply has finished processing. | |
void | nameChanged (const QString &name) |
This signal is emitted when the lookup \l name changes. | |
void | typeChanged (Type type) |
This signal is emitted when the lookup \l type changes. | |
void | nameserverChanged (const QHostAddress &nameserver) |
void | nameserverPortChanged (quint16 port) |
![]() | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
Public Member Functions | |
QDnsLookup (QObject *parent=nullptr) | |
Constructs a QDnsLookup object and sets parent as the parent object. | |
QDnsLookup (Type type, const QString &name, QObject *parent=nullptr) | |
Constructs a QDnsLookup object for the given type and name and sets parent as the parent object. | |
QDnsLookup (Type type, const QString &name, const QHostAddress &nameserver, QObject *parent=nullptr) | |
QDnsLookup (Type type, const QString &name, const QHostAddress &nameserver, quint16 port, QObject *parent=nullptr) | |
~QDnsLookup () | |
Destroys the QDnsLookup object. | |
Error | error () const |
QString | errorString () const |
bool | isFinished () const |
Returns whether the reply has finished or was aborted. | |
QString | name () const |
void | setName (const QString &name) |
QBindable< QString > | bindableName () |
Type | type () const |
void | setType (QDnsLookup::Type) |
QBindable< Type > | bindableType () |
QHostAddress | nameserver () const |
void | setNameserver (const QHostAddress &nameserver) |
QBindable< QHostAddress > | bindableNameserver () |
quint16 | nameserverPort () const |
void | setNameserverPort (quint16 port) |
QBindable< quint16 > | bindableNameserverPort () |
void | setNameserver (const QHostAddress &nameserver, quint16 port) |
QList< QDnsDomainNameRecord > | canonicalNameRecords () const |
Returns the list of canonical name records associated with this lookup. | |
QList< QDnsHostAddressRecord > | hostAddressRecords () const |
Returns the list of host address records associated with this lookup. | |
QList< QDnsMailExchangeRecord > | mailExchangeRecords () const |
Returns the list of mail exchange records associated with this lookup. | |
QList< QDnsDomainNameRecord > | nameServerRecords () const |
Returns the list of name server records associated with this lookup. | |
QList< QDnsDomainNameRecord > | pointerRecords () const |
Returns the list of pointer records associated with this lookup. | |
QList< QDnsServiceRecord > | serviceRecords () const |
Returns the list of service records associated with this lookup. | |
QList< QDnsTextRecord > | textRecords () const |
Returns the list of text records associated with this lookup. | |
![]() | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Properties | |
Error | error |
the type of error that occurred if the DNS lookup failed, or NoError. | |
QString | errorString |
a human-readable description of the error if the DNS lookup failed. | |
QString | name |
the name to lookup. | |
Type | type |
the type of DNS lookup. | |
QHostAddress | nameserver |
the nameserver to use for DNS lookup. | |
quint16 | nameserverPort |
the port number of nameserver to use for DNS lookup. | |
![]() | |
QString | objectName |
the name of this object | |
Additional Inherited Members | |
![]() | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
![]() | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
The QDnsLookup class represents a DNS lookup.
\inmodule QtNetwork
QDnsLookup uses the mechanisms provided by the operating system to perform DNS lookups. To perform a lookup you need to specify a \l name and \l type then invoke the \l{QDnsLookup::lookup()}{lookup()} slot. The \l{QDnsLookup::finished()}{finished()} signal will be emitted upon completion.
For example, you can determine which servers an XMPP chat client should connect to for a given domain with:
Once the request finishes you can handle the results with:
Definition at line 140 of file qdnslookup.h.
enum QDnsLookup::Error |
Indicates all possible error conditions found during the processing of the DNS lookup.
\value NoError no error condition.
\value ResolverError there was an error initializing the system's DNS resolver.
\value OperationCancelledError the lookup was aborted using the abort() method.
\value InvalidRequestError the requested DNS lookup was invalid.
\value InvalidReplyError the reply returned by the server was invalid.
\value ServerFailureError the server encountered an internal failure while processing the request (SERVFAIL).
\value ServerRefusedError the server refused to process the request for security or policy reasons (REFUSED).
\value NotFoundError the requested domain name does not exist (NXDOMAIN).
\value TimeoutError the server was not reached or did not reply in time (since 6.6).
Enumerator | |
---|---|
NoError | |
ResolverError | |
OperationCancelledError | |
InvalidRequestError | |
InvalidReplyError | |
ServerFailureError | |
ServerRefusedError | |
NotFoundError | |
TimeoutError |
Definition at line 153 of file qdnslookup.h.
enum QDnsLookup::Type |
Indicates the type of DNS lookup that was performed.
\value A IPv4 address records.
\value AAAA IPv6 address records.
\value ANY any records.
\value CNAME canonical name records.
\value MX mail exchange records.
\value NS name server records.
\value PTR pointer records.
\value SRV service records.
\value TXT text records.
Enumerator | |
---|---|
A | |
AAAA | |
ANY | |
CNAME | |
MX | |
NS | |
PTR | |
SRV | |
TXT |
Definition at line 167 of file qdnslookup.h.
Constructs a QDnsLookup object and sets parent as the parent object.
The \l type property will default to QDnsLookup::A.
Definition at line 245 of file qdnslookup.cpp.
Constructs a QDnsLookup object for the given type and name and sets parent as the parent object.
Definition at line 255 of file qdnslookup.cpp.
QDnsLookup::QDnsLookup | ( | Type | type, |
const QString & | name, | ||
const QHostAddress & | nameserver, | ||
QObject * | parent = nullptr |
||
) |
Constructs a QDnsLookup object to issue a query for name of record type type, using the DNS server nameserver running on the default DNS port, and sets parent as the parent object.
Definition at line 272 of file qdnslookup.cpp.
QDnsLookup::QDnsLookup | ( | Type | type, |
const QString & | name, | ||
const QHostAddress & | nameserver, | ||
quint16 | port, | ||
QObject * | parent = nullptr |
||
) |
\fn QDnsLookup::QDnsLookup(Type type, const QString &name, const QHostAddress &nameserver, quint16 port, QObject *parent) \since 6.6 Constructs a QDnsLookup object to issue a query for \a name of record type \a type, using the DNS server \a nameserver running on port \a port, and sets \a parent as the parent object.
! [nameserver-port]
Definition at line 292 of file qdnslookup.cpp.
References d, name, nameserver, and type.
QDnsLookup::~QDnsLookup | ( | ) |
Destroys the QDnsLookup object.
It is safe to delete a QDnsLookup object even if it is not finished, you will simply never receive its results.
Definition at line 309 of file qdnslookup.cpp.
|
slot |
Aborts the DNS lookup operation.
If the lookup is already finished, does nothing.
Definition at line 532 of file qdnslookup.cpp.
References d, emit, finished(), OperationCancelledError, and tr.
Definition at line 365 of file qdnslookup.cpp.
References d.
QBindable< QHostAddress > QDnsLookup::bindableNameserver | ( | ) |
Definition at line 409 of file qdnslookup.cpp.
References d.
Definition at line 433 of file qdnslookup.cpp.
References d.
QBindable< QDnsLookup::Type > QDnsLookup::bindableType | ( | ) |
Definition at line 387 of file qdnslookup.cpp.
References d.
QList< QDnsDomainNameRecord > QDnsLookup::canonicalNameRecords | ( | ) | const |
Returns the list of canonical name records associated with this lookup.
Definition at line 459 of file qdnslookup.cpp.
QDnsLookup::Error QDnsLookup::error | ( | ) | const |
Definition at line 318 of file qdnslookup.cpp.
QString QDnsLookup::errorString | ( | ) | const |
Definition at line 328 of file qdnslookup.cpp.
|
signal |
QList< QDnsHostAddressRecord > QDnsLookup::hostAddressRecords | ( | ) | const |
Returns the list of host address records associated with this lookup.
Definition at line 468 of file qdnslookup.cpp.
bool QDnsLookup::isFinished | ( | ) | const |
Returns whether the reply has finished or was aborted.
Definition at line 337 of file qdnslookup.cpp.
|
slot |
Performs the DNS lookup.
The \l{QDnsLookup::finished()}{finished()} signal is emitted upon completion.
Definition at line 551 of file qdnslookup.cpp.
References Qt::BlockingQueuedConnection, QObject::connect(), d, emit, QNetworkReply::error(), QIODevice::errorString(), finished(), QDnsLookupRunnable::finished(), QCoreApplication::instance(), qDebug, qPrintable, qWarning, reply, and QObject::sender().
QList< QDnsMailExchangeRecord > QDnsLookup::mailExchangeRecords | ( | ) | const |
Returns the list of mail exchange records associated with this lookup.
The records are sorted according to \l{http://www.rfc-editor.org/rfc/rfc5321.txt}{RFC 5321}, so if you use them to connect to servers, you should try them in the order they are listed.
Definition at line 481 of file qdnslookup.cpp.
QString QDnsLookup::name | ( | ) | const |
Definition at line 354 of file qdnslookup.cpp.
This signal is emitted when the lookup \l name changes.
name is the new lookup name.
QHostAddress QDnsLookup::nameserver | ( | ) | const |
Definition at line 398 of file qdnslookup.cpp.
|
signal |
quint16 QDnsLookup::nameserverPort | ( | ) | const |
Definition at line 422 of file qdnslookup.cpp.
QList< QDnsDomainNameRecord > QDnsLookup::nameServerRecords | ( | ) | const |
Returns the list of name server records associated with this lookup.
Definition at line 490 of file qdnslookup.cpp.
QList< QDnsDomainNameRecord > QDnsLookup::pointerRecords | ( | ) | const |
Returns the list of pointer records associated with this lookup.
Definition at line 499 of file qdnslookup.cpp.
QList< QDnsServiceRecord > QDnsLookup::serviceRecords | ( | ) | const |
Returns the list of service records associated with this lookup.
The records are sorted according to \l{http://www.rfc-editor.org/rfc/rfc2782.txt}{RFC 2782}, so if you use them to connect to servers, you should try them in the order they are listed.
Definition at line 512 of file qdnslookup.cpp.
Definition at line 359 of file qdnslookup.cpp.
void QDnsLookup::setNameserver | ( | const QHostAddress & | nameserver | ) |
Definition at line 403 of file qdnslookup.cpp.
References d, and nameserver.
Referenced by setNameserver().
void QDnsLookup::setNameserver | ( | const QHostAddress & | nameserver, |
quint16 | port | ||
) |
nameserver-port
Definition at line 447 of file qdnslookup.cpp.
References Qt::beginPropertyUpdateGroup(), Qt::endPropertyUpdateGroup(), nameserver, setNameserver(), and setNameserverPort().
Definition at line 427 of file qdnslookup.cpp.
References d, and nameserverPort.
Referenced by setNameserver().
void QDnsLookup::setType | ( | QDnsLookup::Type | ) |
Definition at line 381 of file qdnslookup.cpp.
QList< QDnsTextRecord > QDnsLookup::textRecords | ( | ) | const |
Returns the list of text records associated with this lookup.
Definition at line 521 of file qdnslookup.cpp.
QDnsLookup::Type QDnsLookup::type | ( | ) | const |
Definition at line 376 of file qdnslookup.cpp.
This signal is emitted when the lookup \l type changes.
type is the new lookup type.
|
read |
the type of error that occurred if the DNS lookup failed, or NoError.
Definition at line 135 of file qdnslookup.h.
|
read |
a human-readable description of the error if the DNS lookup failed.
Definition at line 135 of file qdnslookup.h.
|
readwrite |
the name to lookup.
If the name to look up is empty, QDnsLookup will attempt to resolve the root domain of DNS. That query is usually performed with QDnsLookup::type set to \l{QDnsLookup::Type}{NS}.
Definition at line 135 of file qdnslookup.h.
Referenced by QDnsLookup(), QDnsLookup(), and setName().
|
readwrite |
the nameserver to use for DNS lookup.
Definition at line 135 of file qdnslookup.h.
Referenced by QDnsLookup(), setNameserver(), and setNameserver().
|
readwrite |
the port number of nameserver to use for DNS lookup.
Definition at line 135 of file qdnslookup.h.
Referenced by setNameserverPort().
|
readwrite |
the type of DNS lookup.
Definition at line 135 of file qdnslookup.h.
Referenced by QDnsLookup(), QDnsLookup(), and setType().