Wt
4.11.1
|
A signal that propagates events to listeners. More...
#include <Wt/WSignal.h>
Public Member Functions | |
Signal () | |
Creates a signal. | |
virtual Wt::Signals::connection | connect (WObject *target, WObject::Method method) override |
Connects to a slot. More... | |
template<class F > | |
Wt::Signals::connection | connect (F function) |
Connects to a function. More... | |
template<class T , class V , class... B> | |
Wt::Signals::connection | connect (T *target, void(V::*method)(B...)) |
Connects a slot. More... | |
void | emit (A... args) const |
Emits the signal. More... | |
void | operator() (A... args) const |
Emits the signal. More... | |
virtual bool | isConnected () const override |
Returns whether this signal is connected. More... | |
Public Member Functions inherited from Wt::SignalBase | |
template<class T , class V > | |
Wt::Signals::connection | connect (T *target, void(V::*method)()) |
Connects to a slot. More... | |
A signal that propagates events to listeners.
Use Signal/slots to let one object (A) listen to events caused by another object (B). In this scenario, object B provides in its public interface access to a signal, to which object A connects one of its member function (which act as slot). Object A can then signal an event (which triggers the connected callback functions), by emitting the signal. Signal/slot is a generalization of the popular observer pattern used in GUIs.
A signal can provide details of the event, using up to 6 parameters. A slot must have a compatible signature to connect to a signal, based on its parameters. A compatible signature provides the same parameters in the member function, or less (leaving out parameters at the end).
The signal automatically disconnects from the slot when the target is deleted. In addition, the signal may be deleted at any time, in particular also while it is being emitted.
This widget could then be used from another class:
Wt::Signals::connection Wt::Signal< A >::connect | ( | F | function | ) |
Connects to a function.
This variant of the overloaded connect() method supports a template function object (which supports operator ()).
When the receiver function is an object method, the signal will automatically be disconnected when the object is deleted, as long as the object inherits from WObject (or Wt::Core::observable).
The function may leave up to N parameters unbound (e.g. using std::bind placeholders _1 to _N) that may be bound to values passed by the signal.
Wt::Signals::connection Wt::Signal< A >::connect | ( | T * | target, |
void(V::*)(B...) | method | ||
) |
Connects a slot.
The slot is as a method
of an object target
of class T
, which equals class V
, or is a base class of class V
. Thus, the following statement must return a non-null pointer:
In practice, to facilitate automatic disconnects on deletion of the target
, class T
must be also be a descendant of WObject, but this is not enforced by the interface.
|
overridevirtual |
Connects to a slot.
Every signal can be connected to a slot which does not take any arguments (and may thus ignore signal arguments).
Implements Wt::SignalBase.
void Wt::Signal< A >::emit | ( | A... | args | ) | const |
Emits the signal.
The arguments must exactly match the arguments of the target function.
This will cause all connected slots to be triggered, with the given arguments.
|
overridevirtual |
Returns whether this signal is connected.
Returns true when the signal was connected to to at least one slot.
Implements Wt::SignalBase.
void Wt::Signal< A >::operator() | ( | A... | args | ) | const |