CopperSpice API  1.7.2
QDnsLookup Class Reference

The QDnsLookup class represents a DNS lookup. More...

Inheritance diagram for QDnsLookup:
QObject

Public Types

enum  Error
 
enum  Type
 

Public Signals

void finished ()
 
void nameChanged (const QString &name)
 
void nameserverChanged (const QHostAddress &nameserver)
 
void typeChanged (Type type)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

void abort ()
 
void lookup ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QDnsLookup (QObject *parent=nullptr)
 
 QDnsLookup (Type type, const QString &name, const QHostAddress &nameserver, QObject *parent=nullptr)
 
 QDnsLookup (Type type, const QString &name, QObject *parent=nullptr)
 
 ~QDnsLookup ()
 
QList< QDnsDomainNameRecordcanonicalNameRecords () const
 
Error error () const
 
QString errorString () const
 
QList< QDnsHostAddressRecordhostAddressRecords () const
 
bool isFinished () const
 
QList< QDnsMailExchangeRecordmailExchangeRecords () const
 
QString name () const
 
QHostAddress nameserver () const
 
QList< QDnsDomainNameRecordnameServerRecords () const
 
QList< QDnsDomainNameRecordpointerRecords () const
 
QList< QDnsServiceRecordserviceRecords () const
 
void setName (const QString &name)
 
void setNameserver (const QHostAddress &nameserver)
 
void setType (QDnsLookup::Type)
 
QList< QDnsTextRecordtextRecords () const
 
Type type () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &objName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Properties

 error
 
 errorString
 
 name
 
 nameserver
 
 type
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

The 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 then invoke the lookup() slot. The 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:

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();
}

Once the request finishes you can handle the results with:

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();
}
Note
If you simply want to find the IP address(es) associated with a host name, or the host name associated with an IP address you should use QHostInfo instead.

Member Enumeration Documentation

Indicates all possible error conditions found during the processing of the DNS lookup.

ConstantValueDescription
QDnsLookup::NoError 0 no error condition
QDnsLookup:: 1 there was an error initializing the system's DNS resolver
QDnsLookup::ResolverError 2 lookup was aborted using the abort() method
QDnsLookup::OperationCancelledError 3 requested DNS lookup was invalid
QDnsLookup::InvalidRequestError 4 requested DNS lookup was invalid
QDnsLookup::InvalidReplyError 5 reply returned by the server was invalid
QDnsLookup::ServerRefusedError 7 server refused to process the request for security or policy reasons (REFUSED)
QDnsLookup::NotFoundError 7 the requested domain name does not exist (NXDOMAIN)

Indicates the type of DNS lookup that was performed.

ConstantValueDescription
QDnsLookup::A 1 IPv4 address records
QDnsLookup::AAAA 28 IPv6 address records
QDnsLookup::ANY 255 any records
QDnsLookup::CNAME 5 canonical name records
QDnsLookup::MX 15 mail exchange records
QDnsLookup::NS 2 name server records
QDnsLookup::PTR 12 pointer records
QDnsLookup::SRV 33 service records
QDnsLookup::TXT 16 text records

Constructor & Destructor Documentation

QDnsLookup::QDnsLookup ( QObject parent = nullptr)
explicit

Constructs a QDnsLookup object and sets parent as the parent object. The type property will default to QDnsLookup::A.

QDnsLookup::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::QDnsLookup ( Type  type,
const QString name,
const QHostAddress nameserver,
QObject parent = nullptr 
)

Constructs a QDnsLookup object for the given type, name and nameserver and sets parent as the parent object.

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.

Method Documentation

void QDnsLookup::abort ( )
slot

Aborts the DNS lookup operation.

QList< QDnsDomainNameRecord > QDnsLookup::canonicalNameRecords ( ) const

Returns the list of canonical name records associated with this lookup.

Error QDnsLookup::error ( ) const

Returns the type of error which occurred.

QString QDnsLookup::errorString ( ) const

Returns a human readable description of the error which occurred.

void QDnsLookup::finished ( )
signal

This signal is emitted when the reply has finished processing.

QList< QDnsHostAddressRecord > QDnsLookup::hostAddressRecords ( ) const

Returns the list of host address records associated with this lookup.

bool QDnsLookup::isFinished ( ) const

Returns true if the DNS lookup has finished or failed.

void QDnsLookup::lookup ( )
slot

Performs the DNS lookup. The finished signal is emitted upon completion.

QList< QDnsMailExchangeRecord > QDnsLookup::mailExchangeRecords ( ) const

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.

QString QDnsLookup::name ( ) const

Returns the name of the DNS lookup.

void QDnsLookup::nameChanged ( const QString name)
signal

This signal is emitted when the lookup name changes. The new lookup name is name.

QHostAddress QDnsLookup::nameserver ( ) const

Returns the nameserver which will be used for the DNS lookup.

void QDnsLookup::nameserverChanged ( const QHostAddress nameserver)
signal

This signal is emitted when the nameserver changes.

QList< QDnsDomainNameRecord > QDnsLookup::nameServerRecords ( ) const

Returns the list of name server records associated with this lookup.

QList< QDnsDomainNameRecord > QDnsLookup::pointerRecords ( ) const

Returns the list of pointer records associated with this lookup.

QList< QDnsServiceRecord > QDnsLookup::serviceRecords ( ) const

Returns the list of service records associated with this lookup.

void QDnsLookup::setName ( const QString name)

Sets the DNS lookup to name.

void QDnsLookup::setNameserver ( const QHostAddress nameserver)

Sets the nameserver which will be used for the DNS lookup.

void QDnsLookup::setType ( QDnsLookup::Type  )

Sets the type of DNS lookup to perform.

QList< QDnsTextRecord > QDnsLookup::textRecords ( ) const

Returns the list of text records associated with this DNS lookup.

Type QDnsLookup::type ( ) const

Returns the type of DNS lookup which will be performed.

void QDnsLookup::typeChanged ( Type  type)
signal

This signal is emitted when the lookup type changes. The new lookup type is type.

Property Documentation

QDnsLookup::error

The type of error that occurred if the DNS lookup failed, or NoError.

PropertiesClass Methods
read error
notify finished
QDnsLookup::errorString

A human readable description of the error if the DNS lookup failed.

PropertiesClass Methods
read errorString
notify finished
QDnsLookup::name

The name to lookup.

The name will be encoded using IDNA, which means it is unsuitable for querying SRV records compatible with the DNS-SD specification.

PropertiesClass Methods
read name
write setName
notify nameChanged
QDnsLookup::nameserver

The nameserver to use for DNS lookup.

PropertiesClass Methods
read nameserver
write setNameserver
notify nameserverChanged
QDnsLookup::type

The type of DNS lookup.

PropertiesClass Methods
read type
write setType
notify typeChanged