14

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

kayleeFrye_onDeck
  • 6,648
  • 5
  • 69
  • 80
Ivo
  • 3,481
  • 1
  • 25
  • 29
  • possible duplicate of [How to intercept ALL signals emitted by a given event in QT?](http://stackoverflow.com/questions/2072013/how-to-intercept-all-signals-emitted-by-a-given-event-in-qt) – exilit Oct 16 '14 at 07:36
  • If you want to have just one instance of the class, why didn't you use the singleton pattern to control number of objects? – Afshin May 07 '16 at 13:23

2 Answers2

5

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

James Turner
  • 2,425
  • 2
  • 19
  • 24
  • 1
    I built GammaRay from the git repo and could not find where connections are shown (built with Qt 5.7); the Signals panel just showed emission tics. The best I could do as an alternative was to remove the check for QT_DEBUG in qobject.cpp and call dumpObjectInfo() to see all signal/slot connections of the object, otherwise it printed nothing for my -debug-and-release configured Qt build. – remikz Jan 07 '17 at 21:57
1

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

Community
  • 1
  • 1
liaK
  • 11,422
  • 11
  • 48
  • 73
  • 1
    I am aware of signal spy, sorry for not mentioning that. The downside of it, is that it does not allow me to see *all* emitted signals, just specific signal signatures of a single class or instance. – Ivo Sep 20 '10 at 12:12
  • @Ivo, I am not sure whether there is anything which lists all the signals emitted but yes `QSignalMapper` is to track the signals from the specified instance.. – liaK Sep 20 '10 at 12:30
  • Qt maintains a list of signals internally, which is a struct containing at least the string containing the signal name and signature. That much I gathered from looking at the code. However, unfortunately, this is buried very deep in Qt. – Ivo Sep 20 '10 at 15:01