diff options
Diffstat (limited to 'src/network/kernel/qhostinfo.h')
-rw-r--r-- | src/network/kernel/qhostinfo.h | 63 |
1 files changed, 19 insertions, 44 deletions
diff --git a/src/network/kernel/qhostinfo.h b/src/network/kernel/qhostinfo.h index 47db075b44..3942e41498 100644 --- a/src/network/kernel/qhostinfo.h +++ b/src/network/kernel/qhostinfo.h @@ -17,6 +17,7 @@ class QHostInfoPrivate; class Q_NETWORK_EXPORT QHostInfo { + Q_GADGET public: enum HostInfoError { NoError, @@ -48,7 +49,10 @@ public: void setLookupId(int id); int lookupId() const; +#if QT_NETWORK_REMOVED_SINCE(6, 7) static int lookupHost(const QString &name, QObject *receiver, const char *member); +#endif + static int lookupHost(const QString &name, const QObject *receiver, const char *member); static void abortHostLookup(int lookupId); static QHostInfo fromName(const QString &name); @@ -57,59 +61,30 @@ public: #ifdef Q_QDOC template<typename Functor> - static int lookupHost(const QString &name, Functor functor); - template<typename Functor> static int lookupHost(const QString &name, const QObject *context, Functor functor); #else - // lookupHost to a QObject slot - template <typename Func> + // lookupHost to a callable (with context) + template <typename Functor> static inline int lookupHost(const QString &name, - const typename QtPrivate::FunctionPointer<Func>::Object *receiver, - Func slot) + const typename QtPrivate::ContextTypeForFunctor<Functor>::ContextType *receiver, + Functor &&func) { - typedef QtPrivate::FunctionPointer<Func> SlotType; - - typedef QtPrivate::FunctionPointer<void (*)(QHostInfo)> SignalType; - static_assert(int(SignalType::ArgumentCount) >= int(SlotType::ArgumentCount), - "The slot requires more arguments than the signal provides."); - static_assert((QtPrivate::CheckCompatibleArguments<typename SignalType::Arguments, - typename SlotType::Arguments>::value), - "Signal and slot arguments are not compatible."); - static_assert((QtPrivate::AreArgumentsCompatible<typename SlotType::ReturnType, - typename SignalType::ReturnType>::value), - "Return type of the slot is not compatible " - "with the return type of the signal."); - - auto slotObj = new QtPrivate::QSlotObject<Func, typename SlotType::Arguments, void>(slot); - return lookupHostImpl(name, receiver, slotObj, nullptr); + using Prototype = void(*)(QHostInfo); + QtPrivate::AssertCompatibleFunctions<Prototype, Functor>(); + return lookupHostImpl(name, receiver, + QtPrivate::makeCallableObject<Prototype>(std::forward<Functor>(func)), + nullptr); } +#endif // Q_QDOC +#ifndef QT_NO_CONTEXTLESS_CONNECT // lookupHost to a callable (without context) - template <typename Func> - static inline typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction && - !std::is_same<const char *, Func>::value, int>::type - lookupHost(const QString &name, Func slot) - { - return lookupHost(name, nullptr, std::move(slot)); - } - - // lookupHost to a functor or function pointer (with context) - template <typename Func1> - static inline typename std::enable_if<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction && - !std::is_same<const char*, Func1>::value, int>::type - lookupHost(const QString &name, QObject *context, Func1 slot) + template <typename Functor> + static inline int lookupHost(const QString &name, Functor &&slot) { - typedef QtPrivate::FunctionPointer<Func1> SlotType; - - static_assert(int(SlotType::ArgumentCount) <= 1, - "The slot must not require more than one argument"); - - auto slotObj = new QtPrivate::QFunctorSlotObject<Func1, 1, - typename QtPrivate::List<QHostInfo>, - void>(std::move(slot)); - return lookupHostImpl(name, context, slotObj, nullptr); + return lookupHost(name, nullptr, std::forward<Functor>(slot)); } -#endif // Q_QDOC +#endif // QT_NO_CONTEXTLESS_CONNECT private: QHostInfoPrivate *d_ptr; |