Consider the following code.
class MainWindow
{
// ...
Phonon::MediaObject media;
Phonon::AudioOutput audio_output;
};
MainWindow::MainWindow() : audio_output(MusicCategory)
{
//...
QList<EffectDescription> effects =
BackendCapabilities::availableAudioEffects();
media.setCurrentSource(MediaSource("../test.wma"));
Path path = createPath(&media, &audio_output);
Q_ASSERT(path.isValid());
if (!effects.isEmpty())
{
path.insertEffect(effects[2]);
}
media.play();
qDebug() << "Playing...";
}
After the constructor returns, path
and effects
will be destroyed. I've noticed that the media
continues to play even with the effect applied (effects[2]
).
I think I missed something. Even if path
and effects
are destroyed, how does media
continue to play?
As The Path::~Path documentation says:
Destroys this reference to the Path. If the path was valid the connection is not broken as both the source and the sink MediaNodes still keep a reference to the Path.
That means that paths are more like handles than following RAII principles. You have to explicitely call disconnect() to destroy the connection.