我想知道如果我破坏信号发射对象,我是否需要断开信号和插槽 . 这是一个例子:
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的信号,还是会导致内存泄漏或其他一些未定义的行为?
先感谢您 .
2 回答
调用QObject析构函数时,信号会自动断开 . 看看Qt文档:QObject Destructor
您不必手动
disconnect()
信号和插槽,QObject
destroy会自动清除它们 .