Coverage Report

Created: 2026-08-17 07:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/network/kernel/qhostinfo.h
Line
Count
Source
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#ifndef QHOSTINFO_H
6
#define QHOSTINFO_H
7
8
#include <QtNetwork/qtnetworkglobal.h>
9
10
#include <QtCore/qlist.h>
11
#include <QtCore/qmetatype.h>
12
#include <QtCore/qscopedpointer.h>
13
#include <QtNetwork/qhostaddress.h>
14
15
QT_BEGIN_NAMESPACE
16
17
18
class QObject;
19
class QHostInfoPrivate;
20
21
class Q_NETWORK_EXPORT QHostInfo
22
{
23
    Q_GADGET
24
public:
25
    enum HostInfoError {
26
        NoError,
27
        HostNotFound,
28
        UnknownError
29
    };
30
31
    explicit QHostInfo(int lookupId = -1);
32
    QHostInfo(const QHostInfo &d);
33
0
    QHostInfo(QHostInfo &&other) noexcept : d_ptr(std::exchange(other.d_ptr, nullptr)) {}
34
    QHostInfo &operator=(const QHostInfo &d);
35
0
    QHostInfo &operator=(QHostInfo &&other) noexcept { swap(other); return *this; }
36
    ~QHostInfo();
37
38
0
    void swap(QHostInfo &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); }
39
40
    QString hostName() const;
41
    void setHostName(const QString &name);
42
43
    QList<QHostAddress> addresses() const;
44
    void setAddresses(const QList<QHostAddress> &addresses);
45
46
    HostInfoError error() const;
47
    void setError(HostInfoError error);
48
49
    QString errorString() const;
50
    void setErrorString(const QString &errorString);
51
52
    void setLookupId(int id);
53
    int lookupId() const;
54
55
#if QT_NETWORK_REMOVED_SINCE(6, 7)
56
    static int lookupHost(const QString &name, QObject *receiver, const char *member);
57
#endif
58
    static int lookupHost(const QString &name, const QObject *receiver, const char *member);
59
    static void abortHostLookup(int lookupId);
60
61
    static QHostInfo fromName(const QString &name);
62
    static QString localHostName();
63
    static QString localDomainName();
64
    static void clearCache();
65
66
#ifdef Q_QDOC
67
    template<typename Functor>
68
    static int lookupHost(const QString &name, const QObject *context, Functor functor);
69
#else
70
    // lookupHost to a callable (with context)
71
    template <typename Functor>
72
    static inline int lookupHost(const QString &name,
73
                                 const typename QtPrivate::ContextTypeForFunctor<Functor>::ContextType *receiver,
74
                                 Functor &&func)
75
    {
76
        using Prototype = void(*)(QHostInfo);
77
        QtPrivate::AssertCompatibleFunctions<Prototype, Functor>();
78
        return lookupHostImpl(name, receiver,
79
                              QtPrivate::makeCallableObject<Prototype>(std::forward<Functor>(func)),
80
                              nullptr);
81
    }
82
#endif // Q_QDOC
83
84
#ifndef QT_NO_CONTEXTLESS_CONNECT
85
    // lookupHost to a callable (without context)
86
    template <typename Functor>
87
    static inline int lookupHost(const QString &name, Functor &&slot)
88
    {
89
        return lookupHost(name, nullptr, std::forward<Functor>(slot));
90
    }
91
#endif // QT_NO_CONTEXTLESS_CONNECT
92
93
private:
94
    QHostInfoPrivate *d_ptr;
95
0
    Q_DECLARE_PRIVATE(QHostInfo)
Unexecuted instantiation: QHostInfo::d_func()
Unexecuted instantiation: QHostInfo::d_func() const
96
0
97
0
    static int lookupHostImpl(const QString &name,
98
0
                              const QObject *receiver,
99
0
                              QtPrivate::QSlotObjectBase *slotObj,
100
0
                              const char *member);
101
0
102
0
    friend QHostInfo Q_NETWORK_EXPORT qt_qhostinfo_lookup(const QString &name, QObject *receiver,
103
0
                                                          const char *member, bool *valid, int *id);
104
0
};
105
0
106
0
Q_DECLARE_SHARED(QHostInfo)
107
0
108
0
QT_END_NAMESPACE
109
0
110
QT_DECL_METATYPE_EXTERN(QHostInfo, Q_NETWORK_EXPORT)
Unexecuted instantiation: int qRegisterNormalizedMetaType<QHostInfo>(QByteArray const&)
Unexecuted instantiation: QMetaTypeId<QHostInfo>::qt_metatype_id()
111
112
#endif // QHOSTINFO_H