Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
6
QHostInfo::lookupHost(
"qt-project.org"
,
this
, &MyWidget::printResults);
7
8
// To find the host name for 4.2.2.1
9
QHostInfo::lookupHost(
"4.2.2.1"
,
this
, &MyWidget::printResults);
10
//! [0]
11
12
13
//! [1]
14
QHostInfo
info
= QHostInfo::fromName(
"qt-project.org"
);
15
//! [1]
16
17
18
//! [2]
19
QHostInfo::lookupHost(
"www.kde.org"
,
this
, &MyWidget::lookedUp);
20
//! [2]
21
22
23
//! [3]
24
void
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]
39
QHostInfo::lookupHost(
"4.2.2.1"
,
this
, &MyWidget::lookedUp);
40
//! [4]
41
42
43
//! [5]
44
QHostInfo
info
;
45
...
46
if
(!info.addresses().isEmpty()) {
47
QHostAddress address = info.addresses().first();
48
// use the first IP address
49
}
50
//! [5]
info
QHostInfo info
[0]
Definition
src_network_kernel_qhostinfo.cpp:14
qtbase
src
network
doc
snippets
code
src_network_kernel_qhostinfo.cpp
Generated on
for Qt by
1.18.0