From 76e25bdfdf324a85234b7e7273e0956107f84195 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Sat, 29 Apr 2023 22:32:21 +0200 Subject: Remove QStaticSlotObject, use QFunctorSlotObject instead The two slot object types are identical as long as we use a universal reference and perfect forwarding in the respective connect overloads. Change-Id: I999d71707dd045a17156e3bfecd371da7979beb1 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qobject.h | 20 ++++++++++---------- src/corelib/kernel/qobject_impl.h | 24 ------------------------ 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 53c6de654f..95322a9dbd 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -226,20 +226,20 @@ public: //connect to a function pointer (not a member) template static inline typename std::enable_if::ArgumentCount) >= 0, QMetaObject::Connection>::type - connect(const typename QtPrivate::FunctionPointer::Object *sender, Func1 signal, Func2 slot) + connect(const typename QtPrivate::FunctionPointer::Object *sender, Func1 signal, Func2 &&slot) { - return connect(sender, signal, sender, slot, Qt::DirectConnection); + return connect(sender, signal, sender, std::forward(slot), Qt::DirectConnection); } //connect to a function pointer (not a member) template - static inline typename std::enable_if::ArgumentCount) >= 0 && - !QtPrivate::FunctionPointer::IsPointerToMemberFunction, QMetaObject::Connection>::type - connect(const typename QtPrivate::FunctionPointer::Object *sender, Func1 signal, const QObject *context, Func2 slot, + static inline typename std::enable_if>::ArgumentCount) >= 0 && + !QtPrivate::FunctionPointer>::IsPointerToMemberFunction, QMetaObject::Connection>::type + connect(const typename QtPrivate::FunctionPointer::Object *sender, Func1 signal, const QObject *context, Func2 &&slot, Qt::ConnectionType type = Qt::AutoConnection) { typedef QtPrivate::FunctionPointer SignalType; - typedef QtPrivate::FunctionPointer SlotType; + typedef QtPrivate::FunctionPointer> SlotType; static_assert(QtPrivate::HasQ_OBJECT_Macro::Value, "No Q_OBJECT in the class with the signal"); @@ -257,9 +257,9 @@ public: types = QtPrivate::ConnectionTypes::types(); return connectImpl(sender, reinterpret_cast(&signal), context, nullptr, - new QtPrivate::QStaticSlotObject::Value, - typename SignalType::ReturnType>(slot), + typename SignalType::ReturnType>(std::forward(slot)), type, types, &SignalType::Object::staticMetaObject); } @@ -269,9 +269,9 @@ public: QtPrivate::FunctionPointer::ArgumentCount == -1 && !std::is_convertible_v, // don't match old-style connect QMetaObject::Connection>::type - connect(const typename QtPrivate::FunctionPointer::Object *sender, Func1 signal, Func2 slot) + connect(const typename QtPrivate::FunctionPointer::Object *sender, Func1 signal, Func2 &&slot) { - return connect(sender, signal, sender, std::move(slot), Qt::DirectConnection); + return connect(sender, signal, sender, std::forward(slot), Qt::DirectConnection); } //connect to a functor, with a "context" object defining in which event loop is going to be executed diff --git a/src/corelib/kernel/qobject_impl.h b/src/corelib/kernel/qobject_impl.h index 4d6830a3cc..b57d7e50cc 100644 --- a/src/corelib/kernel/qobject_impl.h +++ b/src/corelib/kernel/qobject_impl.h @@ -37,30 +37,6 @@ namespace QtPrivate { { static const int *types() { return nullptr; } }; template struct ConnectionTypes, true> { static const int *types() { static const int t[sizeof...(Args) + 1] = { (QtPrivate::QMetaTypeIdHelper::qt_metatype_id())..., 0 }; return t; } }; - - // implementation of QSlotObjectBase for which the slot is a static function - // Args and R are the List of arguments and the return type of the signal to which the slot is connected. - template class QStaticSlotObject : public QSlotObjectBase - { - typedef QtPrivate::FunctionPointer FuncType; - Func function; - static void impl(int which, QSlotObjectBase *this_, QObject *r, void **a, bool *ret) - { - switch (which) { - case Destroy: - delete static_cast(this_); - break; - case Call: - FuncType::template call(static_cast(this_)->function, r, a); - break; - case Compare: // not implemented - case NumOperations: - Q_UNUSED(ret); - } - } - public: - explicit QStaticSlotObject(Func f) : QSlotObjectBase(&impl), function(f) {} - }; } -- cgit v1.2.3