Search code examples
c++qtqt4signalssignals-slots

How to Track Emitted Signals in QT?


Is there any way to observe all signals which are emitted?

PS. Of course we can write slots for all signals, but that is not I want.


Solution

  • What do you mean by observing? Do you need real time feedback on console, or is logging to file on program exit enough?

    If you need real time feedback on console, you can check then implementation of QTest. There is a -vs command line switch (Qt doc) which enables all signals printout on console (or you can just run your QTest tests with -vs switch, if you need the signals info only in tests, not in actual application).

    The other way is to use QSignalSpy class. It's not ideal however, because you need one spy per every signal, and you have to print the observed signals periodically (there are no notifications in QSignalSpy).

    Edit : The links were archived, but still accessible there :

    Qt Doc : http://web.archive.org/web/20120624024828/http://qt-project.org/doc/qt-4.8/qtestlib-manual.html

    QsignalSpy : http://web.archive.org/web/20141224031214/http://qt-project.org/doc/qt-4.8/qsignalspy.html

    Newer versions of these documents respectively for newer versions of QT on their official site.