Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qhostinfo.h
Go to the documentation of this file.
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
4#ifndef QHOSTINFO_H
5#define QHOSTINFO_H
6
7#include <QtNetwork/qtnetworkglobal.h>
8#include <QtCore/qlist.h>
9#include <QtCore/qscopedpointer.h>
10#include <QtNetwork/qhostaddress.h>
11
13
14
15class QObject;
17
18class Q_NETWORK_EXPORT QHostInfo
19{
20public:
24 UnknownError
25 };
26
27 explicit QHostInfo(int lookupId = -1);
28 QHostInfo(const QHostInfo &d);
29 QHostInfo(QHostInfo &&other) noexcept : d_ptr(std::exchange(other.d_ptr, nullptr)) {}
30 QHostInfo &operator=(const QHostInfo &d);
31 QHostInfo &operator=(QHostInfo &&other) noexcept { swap(other); return *this; }
32 ~QHostInfo();
33
34 void swap(QHostInfo &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); }
35
36 QString hostName() const;
37 void setHostName(const QString &name);
38
39 QList<QHostAddress> addresses() const;
40 void setAddresses(const QList<QHostAddress> &addresses);
41
42 HostInfoError error() const;
43 void setError(HostInfoError error);
44
45 QString errorString() const;
46 void setErrorString(const QString &errorString);
47
48 void setLookupId(int id);
49 int lookupId() const;
50
51 static int lookupHost(const QString &name, QObject *receiver, const char *member);
52 static void abortHostLookup(int lookupId);
53
54 static QHostInfo fromName(const QString &name);
55 static QString localHostName();
56 static QString localDomainName();
57
58#ifdef Q_QDOC
59 template<typename Functor>
60 static int lookupHost(const QString &name, const QObject *context, Functor functor);
61#else
62 // lookupHost to a callable (with context)
63 template <typename Functor>
64 static inline int lookupHost(const QString &name,
66 Functor &&func)
67 {
68 using Prototype = void(*)(QHostInfo);
69 QtPrivate::AssertCompatibleFunctions<Prototype, Functor>();
70 return lookupHostImpl(name, receiver,
71 QtPrivate::makeCallableObject<Prototype>(std::forward<Functor>(func)),
72 nullptr);
73 }
74#endif // Q_QDOC
75
76 // lookupHost to a callable (without context)
77 template <typename Functor>
78 static inline int lookupHost(const QString &name, Functor &&slot)
79 {
80 return lookupHost(name, nullptr, std::forward<Functor>(slot));
81 }
82
83private:
84 QHostInfoPrivate *d_ptr;
85 Q_DECLARE_PRIVATE(QHostInfo)
86
87 static int lookupHostImpl(const QString &name,
88 const QObject *receiver,
90 const char *member);
91
92 friend QHostInfo Q_NETWORK_EXPORT qt_qhostinfo_lookup(const QString &name, QObject *receiver,
93 const char *member, bool *valid, int *id);
94};
95
96Q_DECLARE_SHARED(QHostInfo)
97
99
100QT_DECL_METATYPE_EXTERN(QHostInfo, Q_NETWORK_EXPORT)
101
102#endif // QHOSTINFO_H
The QHostInfo class provides static functions for host name lookups.
Definition qhostinfo.h:19
QHostInfo & operator=(QHostInfo &&other) noexcept
Move-assigns other to this QHostInfo instance.
Definition qhostinfo.h:31
void swap(QHostInfo &other) noexcept
Swaps host-info other with this host-info.
Definition qhostinfo.h:34
QHostInfo(QHostInfo &&other) noexcept
Move-constructs a new QHostInfo from other.
Definition qhostinfo.h:29
static int lookupHost(const QString &name, const typename QtPrivate::ContextTypeForFunctor< Functor >::ContextType *receiver, Functor &&func)
Definition qhostinfo.h:64
HostInfoError
This enum describes the various errors that can occur when trying to resolve a host name.
Definition qhostinfo.h:21
@ HostNotFound
Definition qhostinfo.h:23
static int lookupHost(const QString &name, Functor &&slot)
Definition qhostinfo.h:78
Definition qlist.h:74
\inmodule QtCore
Definition qobject.h:90
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
Combined button and popup list for selecting options.
static void * context
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
DBusConnection const char DBusError * error
QHostInfo qt_qhostinfo_lookup(const QString &name, QObject *receiver, const char *member, bool *valid, int *id)
#define QT_DECL_METATYPE_EXTERN(TYPE, EXPORT)
Definition qmetatype.h:1367
GLuint name
GLenum func
Definition qopenglext.h:663
static void setError(QJsonObject *response, const QString &msg)
constexpr void qt_ptr_swap(T *&lhs, T *&rhs) noexcept
Definition qswap.h:43
QSharedPointer< T > other(t)
[5]
this swap(other)
proxy setHostName("proxy.example.com")