0

I'm seeing an issue in my QML animation, where very rarely, a state transition animation does not happen. I was searching online why that might be and came across SignalSpy. How and when should someone use it? The example is confusing, I thought it was certain that every time you click a button, the clicked signal would be emitted, why do we need to test this? I was just looking for an explanation that goes beyond the few lines mentioned in the documentation here: https://doc.qt.io/qt-6/qml-qttest-signalspy.html

Evan Krause
  • 147
  • 1
  • 16
  • That's part of QtTest, which is Qt's unit test framework. The example they use in the docs is pretty simplistic, but imagine you have a signal that could be emitted from multiple places, or multiple times from the same place. This allows you to verify that it gets called the number of times you expect. – JarMan May 15 '23 at 22:21
  • The [docs](https://doc.qt.io/qt-6/qsignalspy.html) on the C++ side might give you more insight. – JarMan May 15 '23 at 22:22
  • What could cause it to not emit the number of times we expect it to? I'm trying to understand why we would need a test case like this. @JarMan – Evan Krause May 15 '23 at 22:46
  • 1
    Well, imagine there is some logic behind when you emit a signal, like maybe every time you get a network error, for instance. You just want a simple sanity check that says you got the signal (or didn't). It's not testing Qt's ability to deliver the signal. It's testing that you emitted what you expect to emit. – JarMan May 15 '23 at 23:00
  • 1
    Inspired from this post I added the SignalSpy to my test cases. Guess what...I found out that a dataChanged signal from my data store was triggered two times. Fixed it. Thanks! – Jürgen Lutz May 17 '23 at 06:27
  • Ah...and don't forget to call spy.clear() if you reuse it ;) – Jürgen Lutz May 17 '23 at 06:29

0 Answers0