mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 18:25:37 +08:00
Ref T125, allow to use std::function with CSlot
This commit is contained in:
committed by
Mathew Sutcliffe
parent
d4b027b6bd
commit
8d72fe5285
@@ -78,6 +78,13 @@ namespace BlackMisc
|
||||
CSlot(T *object, R(U::* function)(Args...)) :
|
||||
m_object(object),
|
||||
m_function([ = ](Args... args) { return (object->*function)(args...); })
|
||||
{
|
||||
Q_ASSERT_X(object, Q_FUNC_INFO, "Need object");
|
||||
}
|
||||
|
||||
//! Construct a slot from the given object passing a function
|
||||
CSlot(std::function<R(Args...)> function) :
|
||||
m_function(function)
|
||||
{}
|
||||
|
||||
//! Call the slot. The behaviour is undefined if the slot is empty.
|
||||
@@ -94,6 +101,14 @@ namespace BlackMisc
|
||||
return m_object.data();
|
||||
}
|
||||
|
||||
//! Set the object which the slot belongs to.
|
||||
//! Use this as the third argument to QObject::connect to ensure the slot is called in the correct thread.
|
||||
void setObject(QObject *object)
|
||||
{
|
||||
Q_ASSERT_X(hasNullObject(), Q_FUNC_INFO, "Can only set, not change the object");
|
||||
m_object = object;
|
||||
}
|
||||
|
||||
//! True if the slot can be called, false if it is empty.
|
||||
operator bool() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user