An example of how to connect a member function with arguments to a KDBindings::Signal.
The output of this example is:
Bob received: Have a nice day!
Alice received: Thank you!
#include <iostream>
#include <string>
class Person
{
public:
Person(std::string const &name)
: m_name(name)
{
}
Signal<std::string const &> speak;
void listen(std::string const &message)
{
std::cout << m_name << " received: " << message << std::endl;
}
private:
std::string m_name;
};
int main()
{
Person alice("Alice");
Person bob("Bob");
auto connection1 = alice.speak.connect(&Person::listen, &bob);
auto connection2 = bob.speak.connect(&Person::listen, &alice);
alice.speak.emit("Have a nice day!");
bob.speak.emit("Thank you!");
connection1.disconnect();
connection2.disconnect();
return 0;
}
The main namespace of the KDBindings library.