August 2018
Intermediate to advanced
534 pages
11h 21m
English
The last part we will cover in the Qt Test framework is the ability to spy on signals with QSignalSpy. This class allows you to do the introspection of the emitted signal of any QObject.
Let's see it in action with SoundEffectWidget. We will test QSignalSpy when the SoundEffectWidget::play() function is called, the soundPlayed signal is emitted with the correct soundId parameter.
Here is the playSound() function of TestGui:
#include <QTest> #include "MainWindow.h" // In TestGui.h class TestGui : public QObject { ... void controlButtonState(); void playSound(); ... }; // In TestGui.cpp #include <QPushButton> #include <QtTest/QtTest> #include "SoundEffectWidget.h" ... void TestGui::playSound() { SoundEffectWidget ...Read now
Unlock full access