From 76b06f993e534e02e35830ac0d8f41e546463945 Mon Sep 17 00:00:00 2001 From: Dario Freddi Date: Wed, 17 Jul 2013 00:39:23 +0200 Subject: QObject: allow connecting to functors with a receiver object Up to now, it was only possible to connect to functors in a direct way, without being capable of using Qt::ConnectionType. This patch allows for specifying a receiver for Functors and function pointers, hence making it possible to specify effectively the connection type. To do this properly, it was needed to add an enum in FunctionPointer representing whether the considered function is a member function or not, to reduce ambiguity upon overloaded calls. Moreover, now senders are checked for the existence of a slot obj as well. This way, should the context be freed, the slot obj and the functor contained in it will be freed as well. On a side note, connecting to a static slot (like QCoreApplication::quit) specifying the receiver object is now compiling. Change-Id: I46474099413b1dc6ca4db9934191d469baeef070 Reviewed-by: Olivier Goffart --- src/corelib/kernel/qobjectdefs_impl.h | 52 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'src/corelib/kernel/qobjectdefs_impl.h') diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h index d775ef1b65..fb6601f21b 100644 --- a/src/corelib/kernel/qobjectdefs_impl.h +++ b/src/corelib/kernel/qobjectdefs_impl.h @@ -129,7 +129,7 @@ namespace QtPrivate { its call function is the same as the FunctionPointer::call function. */ #ifndef Q_COMPILER_VARIADIC_TEMPLATES - template struct FunctionPointer { enum {ArgumentCount = -1}; }; + template struct FunctionPointer { enum {ArgumentCount = -1, IsPointerToMemberFunction = false}; }; //Pointers to member functions template struct FunctionPointer { @@ -137,7 +137,7 @@ namespace QtPrivate { typedef void Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (); - enum {ArgumentCount = 0}; + enum {ArgumentCount = 0, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)(), ApplyReturnValue(arg[0]); } }; @@ -147,7 +147,7 @@ namespace QtPrivate { typedef List Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Arg1); - enum {ArgumentCount = 1}; + enum {ArgumentCount = 1, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)((*reinterpret_cast::Type *>(arg[1]))), ApplyReturnValue(arg[0]); @@ -159,7 +159,7 @@ namespace QtPrivate { typedef List > Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Arg1, Arg2); - enum {ArgumentCount = 2}; + enum {ArgumentCount = 2, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -172,7 +172,7 @@ namespace QtPrivate { typedef List > > Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Arg1, Arg2, Arg3); - enum {ArgumentCount = 3}; + enum {ArgumentCount = 3, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -186,7 +186,7 @@ namespace QtPrivate { typedef List > > > Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Arg1, Arg2, Arg3, Arg4); - enum {ArgumentCount = 4}; + enum {ArgumentCount = 4, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -201,7 +201,7 @@ namespace QtPrivate { typedef List > > > > Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Arg1, Arg2, Arg3, Arg4, Arg5); - enum {ArgumentCount = 5}; + enum {ArgumentCount = 5, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -218,7 +218,7 @@ namespace QtPrivate { typedef List > > > > > Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6); - enum {ArgumentCount = 6}; + enum {ArgumentCount = 6, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -237,7 +237,7 @@ namespace QtPrivate { typedef void Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) () const; - enum {ArgumentCount = 0}; + enum {ArgumentCount = 0, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)(), ApplyReturnValue(arg[0]); } }; @@ -247,7 +247,7 @@ namespace QtPrivate { typedef List Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Arg1) const; - enum {ArgumentCount = 1}; + enum {ArgumentCount = 1, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)((*reinterpret_cast::Type *>(arg[1]))), ApplyReturnValue(arg[0]); @@ -259,7 +259,7 @@ namespace QtPrivate { typedef List > Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Arg1, Arg2) const; - enum {ArgumentCount = 2}; + enum {ArgumentCount = 2, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -272,7 +272,7 @@ namespace QtPrivate { typedef List > > Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Arg1, Arg2, Arg3) const; - enum {ArgumentCount = 3}; + enum {ArgumentCount = 3, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -286,7 +286,7 @@ namespace QtPrivate { typedef List > > > Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Arg1, Arg2, Arg3, Arg4) const; - enum {ArgumentCount = 4}; + enum {ArgumentCount = 4, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -301,7 +301,7 @@ namespace QtPrivate { typedef List > > > > Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Arg1, Arg2, Arg3, Arg4, Arg5) const; - enum {ArgumentCount = 5}; + enum {ArgumentCount = 5, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -318,7 +318,7 @@ namespace QtPrivate { typedef List > > > > > Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) const; - enum {ArgumentCount = 6}; + enum {ArgumentCount = 6, IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -336,7 +336,7 @@ namespace QtPrivate { typedef void Arguments; typedef Ret (*Function) (); typedef Ret ReturnType; - enum {ArgumentCount = 0}; + enum {ArgumentCount = 0, IsPointerToMemberFunction = false}; template static void call(Function f, void *, void **arg) { f(), ApplyReturnValue(arg[0]); } }; @@ -345,7 +345,7 @@ namespace QtPrivate { typedef List Arguments; typedef Ret ReturnType; typedef Ret (*Function) (Arg1); - enum {ArgumentCount = 1}; + enum {ArgumentCount = 1, IsPointerToMemberFunction = false}; template static void call(Function f, void *, void **arg) { f(*reinterpret_cast::Value>::Type *>(arg[1])), ApplyReturnValue(arg[0]); } @@ -355,7 +355,7 @@ namespace QtPrivate { typedef List > Arguments; typedef Ret ReturnType; typedef Ret (*Function) (Arg1, Arg2); - enum {ArgumentCount = 2}; + enum {ArgumentCount = 2, IsPointerToMemberFunction = false}; template static void call(Function f, void *, void **arg) { f(*reinterpret_cast::Value>::Type *>(arg[1]), @@ -366,7 +366,7 @@ namespace QtPrivate { typedef List > > Arguments; typedef Ret ReturnType; typedef Ret (*Function) (Arg1, Arg2, Arg3); - enum {ArgumentCount = 3}; + enum {ArgumentCount = 3, IsPointerToMemberFunction = false}; template static void call(Function f, void *, void **arg) { f( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -379,7 +379,7 @@ namespace QtPrivate { typedef List > > > Arguments; typedef Ret ReturnType; typedef Ret (*Function) (Arg1, Arg2, Arg3, Arg4); - enum {ArgumentCount = 4}; + enum {ArgumentCount = 4, IsPointerToMemberFunction = false}; template static void call(Function f, void *, void **arg) { f( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -394,7 +394,7 @@ namespace QtPrivate { List > > > > Arguments; typedef Ret ReturnType; typedef Ret (*Function) (Arg1, Arg2, Arg3, Arg4, Arg5); - enum {ArgumentCount = 5}; + enum {ArgumentCount = 5, IsPointerToMemberFunction = false}; template static void call(Function f, void *, void **arg) { f( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -409,7 +409,7 @@ namespace QtPrivate { typedef List > > > > > Arguments; typedef Ret ReturnType; typedef Ret (*Function) (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6); - enum {ArgumentCount = 6}; + enum {ArgumentCount = 6, IsPointerToMemberFunction = false}; template static void call(Function f, void *, void **arg) { f( *reinterpret_cast::Value>::Type *>(arg[1]), @@ -493,7 +493,7 @@ namespace QtPrivate { template struct Indexes { typedef typename IndexesAppend::Value, N - 1>::Value Value; }; template <> struct Indexes<0> { typedef IndexesList<> Value; }; - template struct FunctionPointer { enum {ArgumentCount = -1}; }; + template struct FunctionPointer { enum {ArgumentCount = -1, IsPointerToMemberFunction = false}; }; template struct FunctorCall; template @@ -521,7 +521,7 @@ namespace QtPrivate { typedef List Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Args...); - enum {ArgumentCount = sizeof...(Args)}; + enum {ArgumentCount = sizeof...(Args), IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { FunctorCall::Value, SignalArgs, R, Function>::call(f, o, arg); @@ -533,7 +533,7 @@ namespace QtPrivate { typedef List Arguments; typedef Ret ReturnType; typedef Ret (Obj::*Function) (Args...) const; - enum {ArgumentCount = sizeof...(Args)}; + enum {ArgumentCount = sizeof...(Args), IsPointerToMemberFunction = true}; template static void call(Function f, Obj *o, void **arg) { FunctorCall::Value, SignalArgs, R, Function>::call(f, o, arg); @@ -545,7 +545,7 @@ namespace QtPrivate { typedef List Arguments; typedef Ret ReturnType; typedef Ret (*Function) (Args...); - enum {ArgumentCount = sizeof...(Args)}; + enum {ArgumentCount = sizeof...(Args), IsPointerToMemberFunction = false}; template static void call(Function f, void *, void **arg) { FunctorCall::Value, SignalArgs, R, Function>::call(f, arg); -- cgit v1.2.3