开发者

Debug Qt signals, slots and connections

开发者 https://www.devze.com 2023-01-16 16:31 出处:网络
Is there a way to see which signals are fired, and if there is a slot connected to them?Ideally, we\'d like to see all signals, not just those of a particular class or method; e.g. QSignalSpy only all

Is there a way to see which signals are fired, and if there is a slot connected to them? Ideally, we'd like to see all signals, not just those of a particular class or method; e.g. QSignalSpy only allows us to track specific signals of specific instances.

In our application, we've seen performance problems because of a signal being emitted twice from different components. In the end, it turned out that there was a second instance of a class that should have only been there once. Knowing whic开发者_运维百科h signals are emitted exactly helps in debugging this.

Signals are called via QMetaObject::invoke*, I was hoping to find something there to hook into, but I found nothing obvious.


(disclaimer, I work for KDAB) : KDAB's GammaRay tool can show you objects and connections at runtime, without requiring any source changes. It inspects the meta-object tables and does some code-injection hooks to make this work.


QSignalSpy could help you.

From docs,

The QSignalSpy class enables introspection of signal emission.QSignalSpy can connect to any signal of any object and records its emission.

The docs has examples too..

0

精彩评论

暂无评论...
验证码 换一张
取 消