diff options
author | Jesus Fernandez <jesus.fernandez@qt.io> | 2016-10-24 21:01:09 +0200 |
---|---|---|
committer | Jesus Fernandez <jesus.fernandez@qt.io> | 2017-01-24 20:54:07 +0000 |
commit | ad5eb297e179a164e297a7c2eb3b9674a1196605 (patch) | |
tree | 925a52ab653dfb0f63c422959f209ea89aae1e48 /src/network/kernel/qhostinfo.h | |
parent | 21f27c9a4d0f2ab0976c144f631c9171c899014b (diff) |
Add QHostInfo::lookupHost overload with modern connect syntax
Task-number: QTBUG-56424
Change-Id: I49053ac2859e6c6c07e4a704b8b5f0d6a2d0b8a4
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/network/kernel/qhostinfo.h')
-rw-r--r-- | src/network/kernel/qhostinfo.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/network/kernel/qhostinfo.h b/src/network/kernel/qhostinfo.h index 9b4a4853d9..4484d718bd 100644 --- a/src/network/kernel/qhostinfo.h +++ b/src/network/kernel/qhostinfo.h @@ -87,8 +87,71 @@ public: static QString localHostName(); static QString localDomainName(); +#ifdef Q_QDOC + template<typename PointerToMemberFunction> + static int QHostInfo::lookupHost(const QString &name, const QObject *receiver, + PointerToMemberFunction function); + template<typename Functor> + static int QHostInfo::lookupHost(const QString &name, Functor functor); + template<typename Functor> + static int QHostInfo::lookupHost(const QString &name, const QObject *context, Functor functor); +#else + // lookupHost to a QObject slot + template <typename Func> + static inline int lookupHost(const QString &name, + const typename QtPrivate::FunctionPointer<Func>::Object *receiver, + Func slot) + { + typedef QtPrivate::FunctionPointer<Func> SlotType; + + typedef QtPrivate::FunctionPointer<void (*)(QHostInfo)> SignalType; + Q_STATIC_ASSERT_X(int(SignalType::ArgumentCount) >= int(SlotType::ArgumentCount), + "The slot requires more arguments than the signal provides."); + Q_STATIC_ASSERT_X((QtPrivate::CheckCompatibleArguments<typename SignalType::Arguments, + typename SlotType::Arguments>::value), + "Signal and slot arguments are not compatible."); + Q_STATIC_ASSERT_X((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); + } + + // 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, 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) + { + typedef QtPrivate::FunctionPointer<Func1> SlotType; + + Q_STATIC_ASSERT_X(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>(slot); + return lookupHostImpl(name, context, slotObj); + } +#endif // Q_QDOC + private: QScopedPointer<QHostInfoPrivate> d; + + static int lookupHostImpl(const QString &name, + const QObject *receiver, + QtPrivate::QSlotObjectBase *slotObj); }; QT_END_NAMESPACE |