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
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{
21public:
25 UnknownError
26 };
27
28 explicit QHostInfo(int lookupId = -1);
29 QHostInfo(const QHostInfo &d);
30 QHostInfo(QHostInfo &&other) noexcept : d_ptr(std::exchange(other.d_ptr, nullptr)) {}
31 QHostInfo &operator=(const QHostInfo &d);
32 QHostInfo &operator=(QHostInfo &&other) noexcept { swap(other); return *this; }
33 ~QHostInfo();
34
35 void swap(QHostInfo &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); }
36
37 QString hostName() const;
38 void setHostName(const QString &name);
39
40 QList<QHostAddress> addresses() const;
41 void setAddresses(const QList<QHostAddress> &addresses);
42
43 HostInfoError error() const;
44 void setError(HostInfoError error);
45
46 QString errorString() const;
47 void setErrorString(const QString &errorString);
48
49 void setLookupId(int id);
50 int lookupId() const;
51
52#if QT_NETWORK_REMOVED_SINCE(6, 7)
53 static int lookupHost(const QString &name, QObject *receiver, const char *member);
54#endif
55 static int lookupHost(const QString &name, const QObject *receiver, const char *member);
56 static void abortHostLookup(int lookupId);
57
58 static QHostInfo fromName(const QString &name);
59 static QString localHostName();
60 static QString localDomainName();
61
62#ifdef Q_QDOC
63 template<typename Functor>
64 static int lookupHost(const QString &name, const QObject *context, Functor functor);
65#else
66 // lookupHost to a callable (with context)
67 template <typename Functor>
68 static inline int lookupHost(const QString &name,
70 Functor &&func)
71 {
72 using Prototype = void(*)(QHostInfo);
73 QtPrivate::AssertCompatibleFunctions<Prototype, Functor>();
74 return lookupHostImpl(name, receiver,
75 QtPrivate::makeCallableObject<Prototype>(std::forward<Functor>(func)),
76 nullptr);
77 }
78#endif // Q_QDOC
79
80#ifndef QT_NO_CONTEXTLESS_CONNECT
81 // lookupHost to a callable (without context)
82 template <typename Functor>
83 static inline int lookupHost(const QString &name, Functor &&slot)
84 {
85 return lookupHost(name, nullptr, std::forward<Functor>(slot));
86 }
87#endif // QT_NO_CONTEXTLESS_CONNECT
88
89private:
90 QHostInfoPrivate *d_ptr;
91 Q_DECLARE_PRIVATE(QHostInfo)
92
93 static int lookupHostImpl(const QString &name,
94 const QObject *receiver,
96 const char *member);
97
98 friend QHostInfo Q_NETWORK_EXPORT qt_qhostinfo_lookup(const QString &name, QObject *receiver,
99 const char *member, bool *valid, int *id);
100};
101
102Q_DECLARE_SHARED(QHostInfo)
103
105
106QT_DECL_METATYPE_EXTERN(QHostInfo, Q_NETWORK_EXPORT)
107
108#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:32
void swap(QHostInfo &other) noexcept
Swaps host-info other with this host-info.
Definition qhostinfo.h:35
QHostInfo(QHostInfo &&other) noexcept
Move-constructs a new QHostInfo from other.
Definition qhostinfo.h:30
static int lookupHost(const QString &name, const typename QtPrivate::ContextTypeForFunctor< Functor >::ContextType *receiver, Functor &&func)
Definition qhostinfo.h:68
HostInfoError
This enum describes the various errors that can occur when trying to resolve a host name.
Definition qhostinfo.h:22
@ HostNotFound
Definition qhostinfo.h:24
static int lookupHost(const QString &name, Functor &&slot)
Definition qhostinfo.h:83
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
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:1388
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:29
#define Q_GADGET
QSharedPointer< T > other(t)
[5]
this swap(other)
proxy setHostName("proxy.example.com")