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

标签 qt signals-slots

我想知道如果我破坏了信号发射对象,我是否需要断开信号和插槽的连接。下面是一个例子:

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)));

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

先感谢您。

最佳答案

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

关于Qt 信号和插槽对象断开连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9264750/

相关文章:

qt - 从 QML 中访问应用程序版本

qt - 如何去除qgraphicsview中绘制的鬼线

python - PyQt:连接对话框中的按钮

c++ - boost 信号 : Expose signal itself or connect/disconnect methods in class interface?

python - PyQt:让小部件在 QDialog 中自动调整大小

c++ - QWidget findChildren when objectname contains a specific string

c++ - 在 QTableWidget c++ qt4 中检测标题点击

c++ - 信号和槽的混淆行为取决于连接类型

c++ - 在线程应用程序中从 QtScript 调用的 Qt 槽

qt - 如果鼠标在小部件窗口外部单击,则关闭小部件窗口