Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
4//! [0]
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);
10//! [0]
11
12
13//! [1]
14QHostInfo info = QHostInfo::fromName("qt-project.org");
15//! [1]
16
17
18//! [2]
19QHostInfo::lookupHost("www.kde.org", this, &MyWidget::lookedUp);
20//! [2]
21
22
23//! [3]
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}
35//! [3]
36
37
38//! [4]
39QHostInfo::lookupHost("4.2.2.1", this, &MyWidget::lookedUp);
40//! [4]
41
42
43//! [5]
45...
46if (!info.addresses().isEmpty()) {
47 QHostAddress address = info.addresses().first();
48 // use the first IP address
49}
50//! [5]
QHostInfo info
[0]