Qt 信号和槽对象断开连接?
我想知道如果我破坏信号发射对象是否需要断开信号和插槽。这是一个示例:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您调用 QObject 析构函数时,信号会自动断开。
查看 Qt 文档: QObject 析构函数
The signals are automatically disconnected when you call the QObject destructor.
Have a look at the Qt documentation: QObject Destructor
您不必手动
disconnect()
信号和槽,QObject
销毁会自动清除它们。You don't have to manually
disconnect()
signals and slots, theQObject
destruction cleans them up automatically.