问题
I understand that a Qt signal is put onto the event queue, and then the connected slots are called later when the event loop sees it. So it doesn't make sense to "step into" it when debugging. But I really do want to see, in a large enough app that I can't keep all of it in mind at once, where the control flow ends up.
So is there a way to find the slot(s) that are connected to a signal, either potentially based on connect(...);
calls or actually at the moment when debugging?
In Qt Creator 3.5.1 (Based on Qt 5.5.1 (GCC 5.2.1 20151129, 64 bit)):
Ctrl+Shift+U
(find usages) only returnsemit signal();
in the source andvoid signal();
in the header.- It'd be really nice if it would also return
connect(..., SIGNAL(signal()), ..., SLOT(slot()));
so I could thenF2
(go to definition) onslot()
and put abreakpoint
in it.
- It'd be really nice if it would also return
- A plaintext search returns a bunch of unrelated signals with the same name in other classes, so that's not really helpful either.
回答1:
You can use New Signal Slot Syntax :
connect(sender, &Sender::valueChanged,receiver, &Receiver::updateValue);
With this connection you can find usage and Qt will find connection line.
来源:https://stackoverflow.com/questions/46573719/follow-an-emitted-signal-to-its-connected-slots