LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
LC::Util::SlotClosure< FireDestrPolicy > Class Template Reference

Executes a given functor upon a signal (or a list of signals). More...

#include "slotclosure.h"

+ Inheritance diagram for LC::Util::SlotClosure< FireDestrPolicy >:
+ Collaboration diagram for LC::Util::SlotClosure< FireDestrPolicy >:

Public Types

using FunType_t = std::function<typename FireDestrPolicy::Signature_t>
 

Public Member Functions

 SlotClosure (const FunType_t &func, QObject *parent)
 Constructs a SlotClosure running a given func with the given parent as a QObject.
 
 SlotClosure (const FunType_t &func, QObject *sender, const char *signal, QObject *parent)
 Constructs a SlotClosure running a given func with the given parent as a QObject on the given signal.
 
 SlotClosure (const FunType_t &func, QObject *sender, const std::initializer_list< const char * > &signalsList, QObject *parent)
 Constructs a SlotClosure running a given func with the given parent as a QObject on the given signalsList.
 
void run () override
 Triggers the function and invokes the destroy policy.
 
- Public Member Functions inherited from LC::Util::SlotClosureBase
virtual ~SlotClosureBase ()=default
 

Additional Inherited Members

- Public Slots inherited from LC::Util::SlotClosureBase

Detailed Description

template<typename FireDestrPolicy>
class LC::Util::SlotClosure< FireDestrPolicy >

Executes a given functor upon a signal (or a list of signals).

Refer to the documentation of SlotClosureBase to check constructors and their parameters.

Typical usage:

const auto reply = networkAccessManager->get (request); // say we want to handle a reply
{
[reply]
{
if (reply->error () == QNetworkReply::NoError)
HandleData (reply->readAll ());
reply->deleteLater ();
},
reply,
SIGNAL (finished ()),
reply
};
Executes a given functor upon a signal (or a list of signals).
Definition slotclosure.h:81

Lifetime management.

The instance of this class can either be deleted after the matching signal is emitted, or when the object's parent object is deleted, or when this object is deleted explicitly by the user. The exact behavior is controlled by the FireDestrPolicy template policy.

There are two predefined policies: DeleteLaterPolicy and NoDeletePolicy.

DeleteLaterPolicy deletes the instance of this class after the signal is fired for the first time.

NoDeletePolicy does not delete the object at all. In this case the object will be deleted either explicitly by the user or when its parent QObject is deleted.

Template Parameters
FireDestrPolicyControls how the object should be destroyed in response to the watched signal.

Definition at line 79 of file slotclosure.h.

Member Typedef Documentation

◆ FunType_t

template<typename FireDestrPolicy >
using LC::Util::SlotClosure< FireDestrPolicy >::FunType_t = std::function<typename FireDestrPolicy::Signature_t>

Definition at line 83 of file slotclosure.h.

Constructor & Destructor Documentation

◆ SlotClosure() [1/3]

template<typename FireDestrPolicy >
LC::Util::SlotClosure< FireDestrPolicy >::SlotClosure ( const FunType_t & func,
QObject * parent )
inline

Constructs a SlotClosure running a given func with the given parent as a QObject.

This constructor does not automatically connect to any signals. Thus, all interesting signals should be manually connected to the construct object's run() slot:

const auto closure = new SlotClosure<DeleteLaterPolicy> { someFunc, parent };
connect (object,
SIGNAL (triggered ()),
closure,
SLOT (run ()));
void run() override
Triggers the function and invokes the destroy policy.
Parameters
[in]funcThe function to run when a connected signal is fired.
[in]parentThe parent object of this SlotClosure.

Definition at line 105 of file slotclosure.h.

◆ SlotClosure() [2/3]

template<typename FireDestrPolicy >
LC::Util::SlotClosure< FireDestrPolicy >::SlotClosure ( const FunType_t & func,
QObject * sender,
const char * signal,
QObject * parent )
inline

Constructs a SlotClosure running a given func with the given parent as a QObject on the given signal.

Parameters
[in]funcThe function to run when a matching signal is fired.
[in]senderThe sender of the signal to connect to.
[in]signalThe signal that should trigger the func.
[in]parentThe parent object of this SlotClosure.

Definition at line 120 of file slotclosure.h.

References LC::Util::SlotClosure< FireDestrPolicy >::run().

+ Here is the call graph for this function:

◆ SlotClosure() [3/3]

template<typename FireDestrPolicy >
LC::Util::SlotClosure< FireDestrPolicy >::SlotClosure ( const FunType_t & func,
QObject * sender,
const std::initializer_list< const char * > & signalsList,
QObject * parent )
inline

Constructs a SlotClosure running a given func with the given parent as a QObject on the given signalsList.

Parameters
[in]funcThe function to run when a matching signal is fired.
[in]senderThe sender of the signal to connect to.
[in]signalsListThe list of signals, any of which triggers the func.
[in]parentThe parent object of this SlotClosure.

Definition at line 143 of file slotclosure.h.

References LC::Util::SlotClosure< FireDestrPolicy >::run().

+ Here is the call graph for this function:

Member Function Documentation

◆ run()

template<typename FireDestrPolicy >
void LC::Util::SlotClosure< FireDestrPolicy >::run ( )
inlineoverridevirtual

Triggers the function and invokes the destroy policy.

Implements LC::Util::SlotClosureBase.

Definition at line 159 of file slotclosure.h.

Referenced by LC::Util::SlotClosure< FireDestrPolicy >::SlotClosure(), and LC::Util::SlotClosure< FireDestrPolicy >::SlotClosure().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: