An example of how to use a ScopedConnection and ConnectionBlocker to manage when a Connection is disconnected or blocked.
Expected output:
Guard is connected: 1
Connection is not blocked: 3
Connection is not blocked: 5
#include <ios>
#include <iostream>
#include <string>
void displayLabelled(const std::string &label, int value)
{
std::cout << label << ": " << value << std::endl;
}
int main()
{
Signal<int> signal;
{
ScopedConnection guard = signal.connect(displayLabelled, "Guard is connected");
signal.emit(1);
}
signal.emit(2);
ConnectionHandle handle = signal.connect(displayLabelled, "Connection is not blocked");
signal.emit(3);
{
ConnectionBlocker blocker(handle);
signal.emit(4);
}
signal.emit(5);
return 0;
}
The main namespace of the KDBindings library.