How can I find the source of a Qt5 signal during a gdb session?

I set a breakpoint in the slot method and ran gdb to debug my Qt5 application . I would like to know where in the code this slot is being called from (via Qt5 system).

My naive approach ends up pausing the program at the breakpoint, but the stack trace is all internal Qt5 elements with no idea which part of the program actually sent the signal to that slot (or the weather was queued or direct call:

enter image description here

Is it possible? How?

Thank!

+4


source to share


2 answers


UPDATED

The only time you won't see a calling signal on the back channel of the stack is when a connection is queued.

For direct connections, you should see something like this:

0 Receiver::baz()           <-- slot function that received the signal
1 Receiver::qt_static_metacall()
2 QMetaObject::activate()
3 Sender::bar()             <-- function with the name of the signal
4 Sender::foo()             <-- function that called emit
5 QWidget::event()
...

      



The situation is more complicated for a queue in a queue. But you can add the following to your slot:

QString __sender__ = sender()->metaObject()->className();

      

This will give you the class name of the object that sent the signal. You can turn it into a macro and dive into your code.

Alternatively, if you have multiple objects of the same class and need to know which one sent the signal, you can use a function sender()

and compare the address of the object, etc.

+4


source


Assuming that a signal and a slot are connected through Qt::QueuedConnection

, I usually put a Qt::QueuedConnection

break on every signal emitting connected to that slot, in this case, if there are not too many of them.



If you otherwise do it temporarily Qt::DirectConnection

(or Qt::BlockingQueuedConnection

applied to streams), you should be able to see the emission in the emitter stream stack trace, waiting for the slot to complete.

+2


source







All Articles