From b8af54a93ffdd2c7e9b781ffbd117558d1b805d1 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sun, 11 Mar 2018 10:49:52 +0100 Subject: QSound(Effect): Convert to functor-style connect Change-Id: Ie58ee30b1ace836c620812b8063246c0d01d7214 Reviewed-by: Christian Stromme --- src/multimedia/audio/qsound.cpp | 3 +- src/multimedia/audio/qsoundeffect.cpp | 14 ++++----- src/multimedia/audio/qsoundeffect_pulse_p.cpp | 34 +++++++++++++--------- src/multimedia/audio/qsoundeffect_qaudio_p.cpp | 18 ++++++------ .../doc/snippets/multimedia-snippets/qsound.cpp | 6 ++-- 5 files changed, 41 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/multimedia/audio/qsound.cpp b/src/multimedia/audio/qsound.cpp index eedea0d76..c6e4f60e0 100644 --- a/src/multimedia/audio/qsound.cpp +++ b/src/multimedia/audio/qsound.cpp @@ -95,7 +95,8 @@ void QSound::play(const QString& filename) // Object destruction is generaly handled via deleteOnComplete // Unexpected cases will be handled via parenting of QSound objects to qApp QSound *sound = new QSound(filename, qApp); - sound->connect(sound->m_soundEffect, SIGNAL(playingChanged()), SLOT(deleteOnComplete())); + sound->connect(sound->m_soundEffect, &QSoundEffect::playingChanged, + sound, &QSound::deleteOnComplete); sound->play(); } diff --git a/src/multimedia/audio/qsoundeffect.cpp b/src/multimedia/audio/qsoundeffect.cpp index 556ba1193..f093373ce 100644 --- a/src/multimedia/audio/qsoundeffect.cpp +++ b/src/multimedia/audio/qsoundeffect.cpp @@ -118,13 +118,13 @@ QSoundEffect::QSoundEffect(QObject *parent) : QObject(parent) { d = new QSoundEffectPrivate(this); - connect(d, SIGNAL(loopsRemainingChanged()), SIGNAL(loopsRemainingChanged())); - connect(d, SIGNAL(volumeChanged()), SIGNAL(volumeChanged())); - connect(d, SIGNAL(mutedChanged()), SIGNAL(mutedChanged())); - connect(d, SIGNAL(loadedChanged()), SIGNAL(loadedChanged())); - connect(d, SIGNAL(playingChanged()), SIGNAL(playingChanged())); - connect(d, SIGNAL(statusChanged()), SIGNAL(statusChanged())); - connect(d, SIGNAL(categoryChanged()), SIGNAL(categoryChanged())); + connect(d, &QSoundEffectPrivate::loopsRemainingChanged, this, &QSoundEffect::loopsRemainingChanged); + connect(d, &QSoundEffectPrivate::volumeChanged, this, &QSoundEffect::volumeChanged); + connect(d, &QSoundEffectPrivate::mutedChanged, this, &QSoundEffect::mutedChanged); + connect(d, &QSoundEffectPrivate::loadedChanged, this, &QSoundEffect::loadedChanged); + connect(d, &QSoundEffectPrivate::playingChanged, this, &QSoundEffect::playingChanged); + connect(d, &QSoundEffectPrivate::statusChanged, this, &QSoundEffect::statusChanged); + connect(d, &QSoundEffectPrivate::categoryChanged, this, &QSoundEffect::categoryChanged); } /*! diff --git a/src/multimedia/audio/qsoundeffect_pulse_p.cpp b/src/multimedia/audio/qsoundeffect_pulse_p.cpp index 77f8607a6..6c8b2a3fd 100644 --- a/src/multimedia/audio/qsoundeffect_pulse_p.cpp +++ b/src/multimedia/audio/qsoundeffect_pulse_p.cpp @@ -154,7 +154,7 @@ private Q_SLOTS: release(); // Try to reconnect later - QTimer::singleShot(30000, this, SLOT(prepare())); + QTimer::singleShot(30000, this, &PulseDaemon::prepare); emit contextFailed(); } @@ -375,7 +375,8 @@ QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): m_resources = QMediaResourcePolicy::createResourceSet(); Q_ASSERT(m_resources); m_resourcesAvailable = m_resources->isAvailable(); - connect(m_resources, SIGNAL(availabilityChanged(bool)), SLOT(handleAvailabilityChanged(bool))); + connect(m_resources, &QMediaPlayerResourceSetInterface::availabilityChanged, + this, &QSoundEffectPrivate::handleAvailabilityChanged); } void QSoundEffectPrivate::handleAvailabilityChanged(bool available) @@ -470,8 +471,8 @@ void QSoundEffectPrivate::setSource(const QUrl &url) if (m_sample) { if (!m_sampleReady) { - disconnect(m_sample, SIGNAL(error()), this, SLOT(decoderError())); - disconnect(m_sample, SIGNAL(ready()), this, SLOT(sampleReady())); + disconnect(m_sample, &QSample::error, this, &QSoundEffectPrivate::decoderError); + disconnect(m_sample, &QSample::ready, this, &QSoundEffectPrivate::sampleReady); } m_sample->release(); m_sample = nullptr; @@ -499,8 +500,8 @@ void QSoundEffectPrivate::setSource(const QUrl &url) setStatus(QSoundEffect::Loading); m_sample = sampleCache()->requestSample(url); - connect(m_sample, SIGNAL(error()), this, SLOT(decoderError())); - connect(m_sample, SIGNAL(ready()), this, SLOT(sampleReady())); + connect(m_sample, &QSample::error, this, &QSoundEffectPrivate::decoderError); + connect(m_sample, &QSample::ready, this, &QSoundEffectPrivate::sampleReady); switch(m_sample->state()) { case QSample::Ready: sampleReady(); @@ -718,8 +719,8 @@ void QSoundEffectPrivate::sampleReady() #ifdef QT_PA_DEBUG qDebug() << this << "sampleReady"; #endif - disconnect(m_sample, SIGNAL(error()), this, SLOT(decoderError())); - disconnect(m_sample, SIGNAL(ready()), this, SLOT(sampleReady())); + disconnect(m_sample, &QSample::error, this, &QSoundEffectPrivate::decoderError); + disconnect(m_sample, &QSample::ready, this, &QSoundEffectPrivate::sampleReady); pa_sample_spec newFormatSpec = audioFormatToSampleSpec(m_sample->format()); if (m_pulseStream && !pa_sample_spec_equal(&m_pulseSpec, &newFormatSpec)) { @@ -752,7 +753,8 @@ void QSoundEffectPrivate::sampleReady() } } else if (!m_pulseStream) { if (!pulseDaemon()->context() || pa_context_get_state(pulseDaemon()->context()) != PA_CONTEXT_READY) { - connect(pulseDaemon(), SIGNAL(contextReady()), SLOT(contextReady())); + connect(pulseDaemon(), &PulseDaemon::contextReady, + this, &QSoundEffectPrivate::contextReady); return; } createPulseStream(); @@ -762,7 +764,7 @@ void QSoundEffectPrivate::sampleReady() void QSoundEffectPrivate::decoderError() { qWarning("QSoundEffect(pulseaudio): Error decoding source"); - disconnect(m_sample, SIGNAL(error()), this, SLOT(decoderError())); + disconnect(m_sample, &QSample::error, this, &QSoundEffectPrivate::decoderError); bool playingDirty = false; if (m_playing) { m_playing = false; @@ -786,7 +788,8 @@ void QSoundEffectPrivate::unloadPulseStream() pa_stream_set_underflow_callback(m_pulseStream, nullptr, nullptr); pa_stream_disconnect(m_pulseStream); pa_stream_unref(m_pulseStream); - disconnect(pulseDaemon(), SIGNAL(contextFailed()), this, SLOT(contextFailed())); + disconnect(pulseDaemon(), &PulseDaemon::contextFailed, + this, &QSoundEffectPrivate::contextFailed); m_pulseStream = nullptr; m_reloadCategory = false; // category will be reloaded when we connect anyway } @@ -1004,7 +1007,8 @@ void QSoundEffectPrivate::createPulseStream() &m_pulseSpec, nullptr, propList); pa_proplist_free(propList); - connect(pulseDaemon(), SIGNAL(contextFailed()), this, SLOT(contextFailed())); + connect(pulseDaemon(), &PulseDaemon::contextFailed, + this, &QSoundEffectPrivate::contextFailed); if (stream == nullptr) { qWarning("QSoundEffect(pulseaudio): Failed to create stream"); @@ -1029,7 +1033,8 @@ void QSoundEffectPrivate::createPulseStream() void QSoundEffectPrivate::contextReady() { - disconnect(pulseDaemon(), SIGNAL(contextReady()), this, SLOT(contextReady())); + disconnect(pulseDaemon(), &PulseDaemon::contextReady, + this, &QSoundEffectPrivate::contextReady); PulseDaemonLocker locker; createPulseStream(); } @@ -1037,7 +1042,8 @@ void QSoundEffectPrivate::contextReady() void QSoundEffectPrivate::contextFailed() { unloadPulseStream(); - connect(pulseDaemon(), SIGNAL(contextReady()), this, SLOT(contextReady())); + connect(pulseDaemon(), &PulseDaemon::contextReady, + this, &QSoundEffectPrivate::contextReady); } void QSoundEffectPrivate::stream_write_callback(pa_stream *s, size_t length, void *userdata) diff --git a/src/multimedia/audio/qsoundeffect_qaudio_p.cpp b/src/multimedia/audio/qsoundeffect_qaudio_p.cpp index bf96f16ae..2c79afddc 100644 --- a/src/multimedia/audio/qsoundeffect_qaudio_p.cpp +++ b/src/multimedia/audio/qsoundeffect_qaudio_p.cpp @@ -125,8 +125,8 @@ void QSoundEffectPrivate::setSource(const QUrl &url) if (d->m_sample) { if (!d->m_sampleReady) { - disconnect(d->m_sample, SIGNAL(error()), d, SLOT(decoderError())); - disconnect(d->m_sample, SIGNAL(ready()), d, SLOT(sampleReady())); + disconnect(d->m_sample, &QSample::error, d, &PrivateSoundSource::decoderError); + disconnect(d->m_sample, &QSample::ready, d, &PrivateSoundSource::sampleReady); } d->m_sample->release(); d->m_sample = nullptr; @@ -134,8 +134,8 @@ void QSoundEffectPrivate::setSource(const QUrl &url) setStatus(QSoundEffect::Loading); d->m_sample = sampleCache()->requestSample(url); - connect(d->m_sample, SIGNAL(error()), d, SLOT(decoderError())); - connect(d->m_sample, SIGNAL(ready()), d, SLOT(sampleReady())); + connect(d->m_sample, &QSample::error, d, &PrivateSoundSource::decoderError); + connect(d->m_sample, &QSample::ready, d, &PrivateSoundSource::sampleReady); switch (d->m_sample->state()) { case QSample::Ready: @@ -328,11 +328,11 @@ void PrivateSoundSource::sampleReady() #ifdef QT_QAUDIO_DEBUG qDebug() << this << "sampleReady "<format()); - connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)), this, SLOT(stateChanged(QAudio::State))); + connect(m_audioOutput, &QAudioOutput::stateChanged, this, &PrivateSoundSource::stateChanged); if (!m_muted) m_audioOutput->setVolume(m_volume); else @@ -348,8 +348,8 @@ void PrivateSoundSource::sampleReady() void PrivateSoundSource::decoderError() { qWarning("QSoundEffect(qaudio): Error decoding source"); - disconnect(m_sample, SIGNAL(ready()), this, SLOT(sampleReady())); - disconnect(m_sample, SIGNAL(error()), this, SLOT(decoderError())); + disconnect(m_sample, &QSample::ready, this, &PrivateSoundSource::sampleReady); + disconnect(m_sample, &QSample::error, this, &PrivateSoundSource::decoderError); m_playing = false; soundeffect->setStatus(QSoundEffect::Error); } diff --git a/src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp b/src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp index 6f1bd7229..fbc849c2e 100644 --- a/src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp +++ b/src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include "qobject.h" +#include "qpushbutton.h" #include "qsound.h" #include "qsoundeffect.h" @@ -74,7 +74,7 @@ void qsoundeffectsnippet() { //! [2] } -QObject *clickSource; +QPushButton *clickSource; class MyGame : public QObject { Q_OBJECT @@ -87,7 +87,7 @@ public: m_explosion.setVolume(0.25f); // Set up click handling etc. - connect(clickSource, SIGNAL(clicked()), &m_explosion, SLOT(play())); + connect(clickSource, &QPushButton::clicked, &m_explosion, &QSoundEffect::play); } private: QSoundEffect m_explosion; -- cgit v1.2.3