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

别说谁变了你拦得住时间么 提交于 2019-12-13 17:53:14

问题


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.

回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!