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>
29 #include <boost/type_traits.hpp>
31 #include <boost/utility/enable_if.hpp>
55 Q_DECLARE_OPERATORS_FOR_FLAGS(ConnectFlags)
57 #if defined(DOXYGEN_RUN)
136 template <
typename T,
typename R,
typename... Args>
137 bool connect(
void *instance,
const char *detailedSignal,
138 T *receiver, R (T::*slot)(Args...), ConnectFlags flags = 0);
192 template <
typename T,
typename R,
typename... Args>
193 bool disconnect(
void *instance,
const char *detailedSignal = 0,
194 T *receiver = 0, R (T::*slot)(Args...) = 0);
202 class QTGLIB_EXPORT ClosureDataBase
205 inline virtual ~ClosureDataBase() {}
206 virtual void marshaller(Value &,
const QList<Value> &) = 0;
211 inline ClosureDataBase(
bool passSender)
212 : passSender(passSender) {}
222 class QTGLIB_EXPORT DestroyNotifierIface
225 virtual ~DestroyNotifierIface() {}
226 virtual bool connect(
void *receiver, QObject *notificationReceiver,
const char *slot) = 0;
227 virtual bool disconnect(
void *receiver, QObject *notificationReceiver) = 0;
230 typedef QSharedPointer<DestroyNotifierIface> DestroyNotifierIfacePtr;
233 class QTGLIB_EXPORT QObjectDestroyNotifier :
public DestroyNotifierIface
236 static DestroyNotifierIfacePtr instance();
238 virtual bool connect(
void *receiver, QObject *notificationReceiver,
const char *slot);
239 virtual bool disconnect(
void *receiver, QObject *notificationReceiver);
247 template <
typename T,
typename Enable =
void>
248 struct GetDestroyNotifier
253 template <
typename T>
254 struct GetDestroyNotifier<T, typename boost::enable_if< boost::is_base_of<QObject, T> >::type>
256 inline operator DestroyNotifierIfacePtr() {
return QObjectDestroyNotifier::instance(); }
261 QTGLIB_EXPORT ulong
connect(
void *instance,
const char *signal, Quark detail,
262 void *receiver,
const DestroyNotifierIfacePtr & notifier,
263 uint slotHash, ClosureDataBase *closureData, ConnectFlags flags);
266 QTGLIB_EXPORT
bool disconnect(
void *instance,
const char *signal, Quark detail,
267 void *receiver, uint slotHash, ulong handlerId);
276 template <
typename T>
277 inline typename boost::enable_if< boost::is_member_function_pointer<T>, uint >::type
278 hashMfp(
const T & mfp)
280 const char *data =
reinterpret_cast<const char*
>(&mfp);
281 return qHash(QByteArray::fromRawData(data,
sizeof(T)));
284 template <
typename T>
285 inline typename boost::enable_if< boost::is_integral<T>, uint >::type
286 hashMfp(
const T & mfp)
297 inline bool disconnect(
void *instance,
const char *detailedSignal = 0,
void *receiver = 0)
299 return Private::disconnect(instance, detailedSignal, Quark(), receiver, 0, 0);
302 template <
typename T>
303 inline bool disconnect(
void *instance,
const char *detailedSignal,
void *receiver, T slot)
305 return Private::disconnect(instance, detailedSignal, Quark(), receiver, Private::hashMfp(slot), 0);
312 #if !QGLIB_HAVE_CXX0X
315 # define QGLIB_CONNECT_MAX_ARGS 9
318 #define IN_QGLIB_CONNECT_H
319 # include "connectimpl.h"
320 #undef IN_QGLIB_CONNECT_H
322 #if defined(QGLIB_CONNECT_MAX_ARGS)
323 # undef QGLIB_CONNECT_MAX_ARGS
Wrappers for Glib and GObject classes.
bool disconnect(void *instance, const char *detailedSignal=0, T *receiver=0, R(T::*slot)(Args...)=0)
bool connect(void *instance, const char *detailedSignal, T *receiver, R(T::*slot)(Args...), ConnectFlags flags=0)