Search code examples
c++qtdebuggingsignals-slots

Follow an emitted signal to its connected slot(s)?


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)):

  1. Ctrl+Shift+U (find usages) only returns emit signal(); in the source and void signal(); in the header.
    • It'd be really nice if it would also return connect(..., SIGNAL(signal()), ..., SLOT(slot())); so I could then F2 (go to definition) on slot() and put a breakpoint in it.
  2. A plaintext search returns a bunch of unrelated signals with the same name in other classes, so that's not really helpful either.

Solution

  • 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.

    sample code image