LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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...
 

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 ( )
delete
Slot ( const Slot< Tsender, Args > &  other)
delete
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 ( 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!!!

Friends And Related Function Documentation

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

Member Data Documentation

QSet<const Signal<Tsender, Args...>*> mSignals
private
Initial value:
{}
~Slot() noexcept { detachAll(); }
int getSignalCount() const noexcept { return mSignals.count(); }
void detachAll() noexcept {
for (auto signal : mSignals) {
signal->mSlots.remove(this);
}
mSignals.clear();
}
Slot& operator=(Slot const& other) = delete

All signals this slot is attached to.

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

The registered callback function.


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