An example of how to use the KDBindings::Signal::connect() overloaded function for advanced slot connections.
The output of this example is:
Hello World!
Emitted value: 5
true
#include <ios>
#include <iostream>
#include <string>
void display()
{
std::cout << "Hello World!" << std::endl;
}
void displayLabelled(const std::string &label, int value)
{
std::cout << label << ": " << value << std::endl;
}
class SignalHandler
{
public:
bool received = 0;
void receive()
{
received = true;
}
};
int main()
{
Signal<int> signal;
std::vector<ConnectionHandle> connections;
connections.emplace_back(signal.connect(display));
connections.emplace_back(signal.connect(displayLabelled, "Emitted value"));
SignalHandler handler;
connections.emplace_back(signal.connect(&SignalHandler::receive, &handler));
signal.emit(5);
std::cout << std::boolalpha << handler.received << std::endl;
for (auto &connection : connections) {
connection.disconnect();
}
return 0;
}
The main namespace of the KDBindings library.