LibrePCB Developers Documentation
Slot< Tsender, Args > Class Template Reference

The Slot class is used to receive signals from non-QObject derived classes. More...

#include <signalslot.h>

+ Inheritance diagram for Slot< Tsender, Args >:
+ Collaboration diagram for Slot< Tsender, Args >:

Public Member Functions

 Slot ()=delete
 
 Slot (const Slot &other)=delete
 
 Slot (const std::function< void(const Tsender &, Args...)> &callback) noexcept
 Constructor. More...
 
template<typename T >
 Slot (T &obj, void(T::*func)(const Tsender &, Args...)) noexcept
 Constructor. More...
 
 ~Slot () noexcept
 Destructor. More...
 
int getSignalCount () const noexcept
 Get the count of registered signals. More...
 
void detachAll () noexcept
 Detach from all signals. More...
 
Slotoperator= (Slot const &other)=delete
 

Private Attributes

QSet< const Signal< Tsender, Args... > * > mSignals
 All signals this slot is attached to. More...
 
std::function< void(const Tsender &, Args...)> mCallback
 The registered callback function. More...
 

Friends

class Signal< Tsender, Args... >
 

Detailed Description

template<typename Tsender, typename... Args>
class librepcb::Slot< Tsender, Args >

The Slot class is used to receive signals from non-QObject derived classes.

Instances of this class allow to connect librepcb::Signal objects to callback functions. Instead of connecting signals directly to callbacks, this indirection allows to automatically disconnect connections if either the sender or the receiver object is destroyed. This avoids potential segfaults due to dereferencing dangling pointers.

A slot can be connected to multiple signals if they have the same signature.

Template Parameters
TsenderType of the sender object
ArgsArguments passed from librepcb::Signal::notify() to the callbacks
See also
librepcb::Signal

Constructor & Destructor Documentation

◆ Slot() [1/4]

Slot ( )
delete

◆ Slot() [2/4]

Slot ( const Slot< Tsender, Args > &  other)
delete

◆ Slot() [3/4]

Slot ( const std::function< void(const Tsender &, Args...)> &  callback)
inlineexplicitnoexcept

Constructor.

Parameters
callbackThe callback to be called if the signal is emitted
Warning
The function must never throw an exception!!!

◆ Slot() [4/4]

Slot ( T &  obj,
void(T::*)(const Tsender &, Args...)  func 
)
inlineexplicitnoexcept

Constructor.

Parameters
objThe object to be called if the signal is emitted
funcThe member function to be called if the signal is emitted
Warning
The function must never throw an exception!!!

◆ ~Slot()

~Slot ( )
inlinenoexcept

Destructor.

Automatically disconnects from all signals.

+ Here is the call graph for this function:

Member Function Documentation

◆ getSignalCount()

int getSignalCount ( ) const
inlinenoexcept

Get the count of registered signals.

Returns
Count of registered signals

◆ detachAll()

void detachAll ( )
inlinenoexcept

Detach from all signals.

+ Here is the caller graph for this function:

◆ operator=()

Slot & operator= ( Slot< Tsender, Args > const &  other)
delete

Friends And Related Function Documentation

◆ Signal< Tsender, Args... >

friend class Signal< Tsender, Args... >
friend

Member Data Documentation

◆ mSignals

QSet<const Signal<Tsender, Args...>*> mSignals
private

All signals this slot is attached to.

◆ mCallback

std::function<void(const Tsender&, Args...)> mCallback
private

The registered callback function.


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