考虑以下代码。
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...";
}
构造函数返回后,path
和effects
会被销毁。我注意到即使应用了效果 (effects[2]
),media
也会继续播放。
我想我错过了什么。即使path
和effects
被破坏,media
如何继续播放?
最佳答案
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.
这意味着路径更像是句柄而不是遵循 RAII 原则。 您必须明确调用 disconnect() 来破坏连接。
关于c++ - Phonon::Path 和 Phonon::Effect 即使被摧毁也能继续工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9483206/