Using Qt 5.11. By overriding QObject::connectNotify
, I can get notified if a slot was connected to my signal:
void connectNotify(const QMetaMethod &signal) override {
if (signal == QMetaMethod::fromSignal(&PromiseBase::resolved()) && isResolved()) {
// Here, I want to call the slot immediately.
}
}
When this happens, I want to immediately call the slot – and just that slot, not all other slots that might be connected to the signal. How can I do this? The Qt framework gives me the signal, but not the slot.
Context: I'm working on a Promise class similar to JavaScript promises. The expectation is that connecting a slot to the resolved
signal will always call the slot exactly once, regardless of whether the promise has been resolved or is still pending.
(I'm writing my own Promise rather than using QFuture, because there is no documented and supported way to create your own QFuture objects, and QFuture has no support for reporting errors.)