Qt 信号和槽对象断开连接?

发布于 2025-01-04 22:36:09 字数 497 浏览 5 评论 0原文

我想知道如果我破坏信号发射对象是否需要断开信号和插槽。这是一个示例:

QAudioOutput * audioOutput = new QAudioOutput(format,mainWindow);
connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(stateChanged(QAudio::State)));

delete audioOutput;

audioOutput = new QAudioOutput(format,mainWindow);
connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(stateChanged(QAudio::State)));

这会自动断开旧音频输出的信号,还是会导致内存泄漏或其他一些未定义的行为?

先感谢您。

I am wondering if i need to disconnect singals and slots if i destroy the signal emitting object. Here is an example:

QAudioOutput * audioOutput = new QAudioOutput(format,mainWindow);
connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(stateChanged(QAudio::State)));

delete audioOutput;

audioOutput = new QAudioOutput(format,mainWindow);
connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(stateChanged(QAudio::State)));

Will this automatically disconnect the signal from the old audioOutput, or will it lead to mem leaks or some other undefined behavior ?

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

朕就是辣么酷 2025-01-11 22:36:09

当您调用 QObject 析构函数时,信号会自动断开。
查看 Qt 文档: QObject 析构函数

The signals are automatically disconnected when you call the QObject destructor.
Have a look at the Qt documentation: QObject Destructor

凯凯我们等你回来 2025-01-11 22:36:09

您不必手动 disconnect() 信号和槽,QObject 销毁会自动清除它们。

You don't have to manually disconnect() signals and slots, the QObject destruction cleans them up automatically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文