Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

Introducing the ConnectionEvaluator in KDBindings

Control When Connections are Emitted

auto evaluator = std::make_shared<ConnectionEvaluator>(); // Shared ownership for proper lifetime management
Signal<int> signal;
int value = 0;

auto connection = signal.connectDeferred(evaluator, [&value](int increment) {
value += increment;
});
signal.emit(5);  // The slot is queued, not executed.
evaluator.evaluateDeferredConnections();  // Executes the queued slot.
Signal<int> workerSignal;
int guiValue = 0;
auto evaluator = std::make_shared<ConnectionEvaluator>();

// Connect a slot to the workerSignal with deferred evaluation
workerSignal.connectDeferred(evaluator, [&guiValue](int value) {
// This slot will be executed later in the GUI thread's event loop
guiValue += value;
});

// ... Worker thread emits signals ...

// In the GUI thread's event loop or at the right time
evaluator->evaluateDeferredConnections();

// The connected slot is now executed, and guiValue is updated

About KDAB