Wt  3.3.8
Public Member Functions | List of all members
Wt::Signal< A1, A2, A3, A4, A5, A6 > Class Template Reference

A signal that propagates events to listeners. More...

#include <Wt/WSignal>

Inheritance diagram for Wt::Signal< A1, A2, A3, A4, A5, A6 >:
Inheritance graph
[legend]

Public Member Functions

 Signal (WObject *sender=0)
 Creates a signal. More...
 
 ~Signal ()
 Destructor.
 
virtual Wt::Signals::connection connect (WObject *target, WObject::Method method)
 Connects to a slot. More...
 
template<class F >
Wt::Signals::connection connect (const F &function)
 Connects to a function. More...
 
template<class T , class V >
Wt::Signals::connection connect (T *target, void(V::*method)())
 Connects a slot that takes no arguments. More...
 
template<class T , class V >
Wt::Signals::connection connect (T *target, void(V::*method)(A1))
 Connects a slot that takes one argument. More...
 
template<class T , class V >
Wt::Signals::connection connect (T *target, void(V::*method)(A1, A2))
 Connects a slot that takes two arguments. More...
 
template<class T , class V >
Wt::Signals::connection connect (T *target, void(V::*method)(A1, A2, A3))
 Connects a slot that takes three arguments. More...
 
template<class T , class V >
Wt::Signals::connection connect (T *target, void(V::*method)(A1, A2, A3, A4))
 Connects a slot that takes four arguments. More...
 
template<class T , class V >
Wt::Signals::connection connect (T *target, void(V::*method)(A1, A2, A3, A4, A5))
 Connects a slot that takes five arguments. More...
 
template<class T , class V >
Wt::Signals::connection connect (T *target, void(V::*method)(A1, A2, A3, A4, A5, A6))
 Connects a slot that takes six arguments. More...
 
void emit (A1 a1=NoClass::none, A2 a2=NoClass::none, A3 a3=NoClass::none, A4 a4=NoClass::none, A5 a5=NoClass::none, A6 a6=NoClass::none) const
 Emits the signal. More...
 
void operator() (A1 a1=NoClass::none, A2 a2=NoClass::none, A3 a3=NoClass::none, A4 a4=NoClass::none, A5 a5=NoClass::none, A6 a6=NoClass::none) const
 Emits the signal. More...
 
virtual bool isConnected () const
 Returns whether this signal is connected. More...
 
- Public Member Functions inherited from Wt::SignalBase
WObjectsender () const
 Returns the sender. More...
 
template<class T , class V >
Wt::Signals::connection connect (T *target, void(V::*method)())
 Connects to a slot. More...
 

Detailed Description

template<typename A1 = NoClass, typename A2 = NoClass, typename A3 = NoClass, typename A4 = NoClass, typename A5 = NoClass, typename A6 = NoClass>
class Wt::Signal< A1, A2, A3, A4, A5, A6 >

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.

The Signal objects integrate with WObject objects. A Signal requires that the target of a connection, i.e. the object that listens for an event, is a WObject. In addition, every signal may specify one WObject to be the owner of the signal, and a target may find out the sender of a signal emission, using WObject::sender().

class MyWidget : public Wt::WContainerWidget
{
public:
MyWidget(Wt::WContainerWidget *parent = 0)
: Wt::WContainerWidget(parent),
done_(this)
{
...
Wt::WPushButton *button = new Wt::WPushButton("Okay");
button->clicked().connect(this, &MyWidget::process);
}
// provide an accessor for the signal
Wt::Signal<int, std::string>& done() { return done_; }
private:
void process() {
...
done_.emit(42, "Totally done"); // emit the signal
}
};

This widget could then be used from another class:

class GUIClass : public Wt::WContainerWidget
{
...
private:
void init() {
MyWidget *widget = new MyWidget(this);
widget->done().connect(this, &GUIClass::whenDone);
}
void whenDone(int result, const std::string& description) {
...
}
};

The WSignalMapper is a utility class that helps in situations where you want to connect multiple signals to a single slot, and still be identify the sender using some property.

See also
WSignalMapper

Constructor & Destructor Documentation

template<typename A1 , typename A2 , typename A3 , typename A4 , typename A5 , typename A6 >
Wt::Signal< A1, A2, A3, A4, A5, A6 >::Signal ( WObject sender = 0)

Creates a signal.

The sender is the object that will be identified as WObject::sender() when executing connected slots may be passed as an argument.

The sender should not be 0 when you want to map the signal using the WSignalMapper.

Member Function Documentation

template<typename A1 , typename A2 , typename A3 , typename A4 , typename A5 , typename A6 >
Wt::Signals::connection Wt::Signal< A1, A2, A3, A4, A5, A6 >::connect ( WObject target,
WObject::Method  method 
)
virtual

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.

template<typename A1 , typename A2 , typename A3 , typename A4 , typename A5 , typename A6 >
template<class F >
Wt::Signals::connection Wt::Signal< A1, A2, A3, A4, A5, A6 >::connect ( const 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::Signals::trackable).

The function may leave up to N parameters unbound (e.g. using boost::bind placeholders _1 to _N) that may be bound to values passed by the signal.

template<typename A1 , typename A2 , typename A3 , typename A4 , typename A5 , typename A6 >
template<class T , class V >
Wt::Signals::connection Wt::Signal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)()  method 
)

Connects a slot that takes no arguments.

This is always possible (even when the signal specifies a number of arguments).

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:

V *v = dynamic_cast<V *>(target);

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.

template<typename A1, typename A2 , typename A3 , typename A4 , typename A5 , typename A6 >
template<class T , class V >
Wt::Signals::connection Wt::Signal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)(A1)  method 
)

Connects a slot that takes one argument.

This is only possible for signals that take at least one argument.

See also
connect(T *target, void (V::*method)())
template<typename A1, typename A2, typename A3 , typename A4 , typename A5 , typename A6 >
template<class T , class V >
Wt::Signals::connection Wt::Signal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)(A1, A2)  method 
)

Connects a slot that takes two arguments.

This is only possible for signals that take at least two arguments.

See also
connect(T *target, void (V::*method)())
template<typename A1, typename A2, typename A3, typename A4 , typename A5 , typename A6 >
template<class T , class V >
Wt::Signals::connection Wt::Signal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)(A1, A2, A3)  method 
)

Connects a slot that takes three arguments.

This is only possible for signals that take at least three arguments.

See also
connect(T *target, void (V::*method)())
template<typename A1, typename A2, typename A3, typename A4, typename A5 , typename A6 >
template<class T , class V >
Wt::Signals::connection Wt::Signal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)(A1, A2, A3, A4)  method 
)

Connects a slot that takes four arguments.

This is only possible for signals that take at least four arguments.

See also
connect(T *target, void (V::*method)())
template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6 >
template<class T , class V >
Wt::Signals::connection Wt::Signal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)(A1, A2, A3, A4, A5)  method 
)

Connects a slot that takes five arguments.

This is only possible for signals that take at least five arguments.

See also
connect(T *target, void (V::*method)())
template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
template<class T , class V >
Wt::Signals::connection Wt::Signal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)(A1, A2, A3, A4, A5, A6)  method 
)

Connects a slot that takes six arguments.

This is only possible for signals that take at least six arguments.

See also
connect(T *target, void (V::*method)())
template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
void Wt::Signal< A1, A2, A3, A4, A5, A6 >::emit ( A1  a1 = NoClass::none,
A2  a2 = NoClass::none,
A3  a3 = NoClass::none,
A4  a4 = NoClass::none,
A5  a5 = NoClass::none,
A6  a6 = NoClass::none 
) 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.

template<typename A1 , typename A2 , typename A3 , typename A4 , typename A5 , typename A6 >
bool Wt::Signal< A1, A2, A3, A4, A5, A6 >::isConnected ( ) const
virtual

Returns whether this signal is connected.

Returns true when the signal was connected to to at least one slot.

Implements Wt::SignalBase.

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
void Wt::Signal< A1, A2, A3, A4, A5, A6 >::operator() ( A1  a1 = NoClass::none,
A2  a2 = NoClass::none,
A3  a3 = NoClass::none,
A4  a4 = NoClass::none,
A5  a5 = NoClass::none,
A6  a6 = NoClass::none 
) const

Emits the signal.

This is equivalent to emit().

See also
emit

Generated on Mon Sep 4 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11