19 #ifndef QGLIB_CONNECT_H
20 #define QGLIB_CONNECT_H
24 #include <QtCore/QObject>
25 #include <QtCore/QSharedPointer>
26 #include <QtCore/QFlags>
27 #include <QtCore/QHash>
28 #include <boost/type_traits.hpp>
29 #include <boost/utility/enable_if.hpp>
53 Q_DECLARE_OPERATORS_FOR_FLAGS(ConnectFlags)
55 #if defined(DOXYGEN_RUN)
134 template <
typename T,
typename R,
typename... Args>
135 bool connect(
void *instance,
const char *detailedSignal,
136 T *receiver, R (T::*slot)(Args...), ConnectFlags flags = 0);
190 template <
typename T,
typename R,
typename... Args>
191 bool disconnect(
void *instance,
const char *detailedSignal = 0,
192 T *receiver = 0, R (T::*slot)(Args...) = 0);
200 class QTGLIB_EXPORT ClosureDataBase
203 inline virtual ~ClosureDataBase() {}
204 virtual void marshaller(Value &,
const QList<Value> &) = 0;
209 inline ClosureDataBase(
bool passSender)
210 : passSender(passSender) {}
220 class QTGLIB_EXPORT DestroyNotifierIface
223 virtual ~DestroyNotifierIface() {}
224 virtual bool connect(
void *receiver, QObject *notificationReceiver,
const char *slot) = 0;
225 virtual bool disconnect(
void *receiver, QObject *notificationReceiver) = 0;
228 typedef QSharedPointer<DestroyNotifierIface> DestroyNotifierIfacePtr;
231 class QTGLIB_EXPORT QObjectDestroyNotifier :
public DestroyNotifierIface
234 static DestroyNotifierIfacePtr instance();
236 virtual bool connect(
void *receiver, QObject *notificationReceiver,
const char *slot);
237 virtual bool disconnect(
void *receiver, QObject *notificationReceiver);
245 template <
typename T,
typename Enable =
void>
246 struct GetDestroyNotifier
251 template <
typename T>
252 struct GetDestroyNotifier<T, typename boost::enable_if< boost::is_base_of<QObject, T> >::type>
254 inline operator DestroyNotifierIfacePtr() {
return QObjectDestroyNotifier::instance(); }
259 QTGLIB_EXPORT ulong
connect(
void *instance,
const char *signal, Quark detail,
260 void *receiver,
const DestroyNotifierIfacePtr & notifier,
261 uint slotHash, ClosureDataBase *closureData, ConnectFlags flags);
264 QTGLIB_EXPORT
bool disconnect(
void *instance,
const char *signal, Quark detail,
265 void *receiver, uint slotHash, ulong handlerId);
274 template <
typename T>
275 inline typename boost::enable_if< boost::is_member_function_pointer<T>, uint >::type
276 hashMfp(
const T & mfp)
278 const char *data =
reinterpret_cast<const char*
>(&mfp);
279 return qHash(QByteArray::fromRawData(data,
sizeof(T)));
282 template <
typename T>
283 inline typename boost::enable_if< boost::is_integral<T>, uint >::type
284 hashMfp(
const T & mfp)
295 inline bool disconnect(
void *instance,
const char *detailedSignal = 0,
void *receiver = 0)
297 return Private::disconnect(instance, detailedSignal, Quark(), receiver, 0, 0);
300 template <
typename T>
301 inline bool disconnect(
void *instance,
const char *detailedSignal,
void *receiver, T slot)
303 return Private::disconnect(instance, detailedSignal, Quark(), receiver, Private::hashMfp(slot), 0);
310 #if !QGLIB_HAVE_CXX0X
313 # define QGLIB_CONNECT_MAX_ARGS 9
316 #define IN_QGLIB_CONNECT_H
317 # include "connectimpl.h"
318 #undef IN_QGLIB_CONNECT_H
320 #if defined(QGLIB_CONNECT_MAX_ARGS)
321 # undef QGLIB_CONNECT_MAX_ARGS
324 #endif //QGLIB_CONNECT_H