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

标签 c++ qt phonon

考虑以下代码。

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/

相关文章:

c++ - multimap 运算符函数错误

c++ - 对智能指针范围的困惑

c++ - ifstream、无缓冲读取和无预读缓存?

c++ - 在类中分配过多动态内存时,Qt 会抛出错误

python - 如何使用PyQt4点击网页上 'alert'消息中的按钮

python - 使用 QWebView 和 HTML5 音频 API 创建 python 音频播放器

c++ - Linux 上的 Qt Phonon - 没有这样的文件或目录

c++ - 在多核机器上使用 boost asio 只有 1 个线程

qt - ROS Qt 媒体在重新制作之前不显示

qt - 实现 updatePaintNode 会导致其他 QML 元素也无法正确绘制