Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_network_kernel_qhostinfo.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
5// To find the IP address of qt-project.org
6QHostInfo::lookupHost("qt-project.org", this, &MyWidget::printResults);
7
8// To find the host name for 4.2.2.1
9QHostInfo::lookupHost("4.2.2.1", this, &MyWidget::printResults);
11
12
16
17
19QHostInfo::lookupHost("www.kde.org", this, &MyWidget::lookedUp);
21
22
24void MyWidget::lookedUp(const QHostInfo &host)
25{
26 if (host.error() != QHostInfo::NoError) {
27 qDebug() << "Lookup failed:" << host.errorString();
28 return;
29 }
30
31 const auto addresses = host.addresses();
32 for (const QHostAddress &address : addresses)
33 qDebug() << "Found address:" << address.toString();
34}
36
37
39QHostInfo::lookupHost("4.2.2.1", this, &MyWidget::lookedUp);
41
42
45...
48 // use the first IP address
49}
The QHostAddress class provides an IP address.
The QHostInfo class provides static functions for host name lookups.
Definition qhostinfo.h:19
static int lookupHost(const QString &name, const QObject *receiver, const char *member)
Looks up the IP address(es) associated with host name name, and returns an ID for the lookup.
HostInfoError error() const
Returns the type of error that occurred if the host name lookup failed; otherwise returns NoError.
QString errorString() const
If the lookup failed, this function returns a human readable description of the error; otherwise "Unk...
static QHostInfo fromName(const QString &name)
Looks up the IP address(es) for the given host name.
QList< QHostAddress > addresses() const
Returns the list of IP addresses associated with hostName().
bool isEmpty() const noexcept
Definition qlist.h:401
T & first()
Definition qlist.h:645
#define qDebug
[1]
Definition qlogging.h:164
GLuint GLuint64EXT address
QHostInfo info
[0]
char * toString(const MyType &t)
[31]