#include "sound.h" #include #include #include #include Sound::Sound(QObject *parent) : QObject(parent) { appendSound(TestType, "qrc:/audio/test.wav"); appendSound(InfoType, "qrc:/audio/info.wav"); appendSound(WarningType, "qrc:/audio/warning.wav"); appendSound(AlertType, "qrc:/audio/alert.wav"); appendSound(WakeUpType, "qrc:/audio/wakeup.wav"); appendSound(ClickType, "qrc:/audio/click.wav"); } void Sound::appendSound(Type type, const QString &source) { const auto effect = new QSoundEffect(this); effect->setSource(source); connect(this, &Sound::volumeChanged, effect, &QSoundEffect::setVolume, Qt::QueuedConnection); _effects.insert(type, effect); } void Sound::test() { static auto i = 0; i++; auto volume = QRandomGenerator::global()->generateDouble(); qDebug().noquote() << QString("attempt %1 set volume %2").arg(i).arg(volume); Q_EMIT volumeChanged(volume); if (i < 100000) QTimer::singleShot(20, this, &Sound::test); }