gpt4 book ai didi

c++ - Phonon::Path 和 Phonon::Effect 即使被摧毁也能继续工作

转载 作者:太空宇宙 更新时间:2023-11-04 12:11:47 25 4
gpt4 key购买 nike

考虑以下代码。

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...";
}

构造函数返回后,patheffects会被销毁。我注意到即使应用了效果 (effects[2]),media 也会继续播放。

我想我错过了什么。即使patheffects被破坏,media如何继续播放?

最佳答案

作为Path::~Path documentation说:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com