PDA

View Full Version : QT: Create new connections when signal is emitted



LucaDanieli
5th February 2017, 16:32
Hello, I would like to create a SLOT that establish some connections between classes. Something like this:


void MainWindow::onDocumentDockletUndocked( bool isFloating )
{
if(isFloating) {
foreach(MultiEditor * me, mEditorList) {
connect(me, SIGNAL(currentDocumentChanged(Document*)),
mDocumentsDocklet, SLOT(setCurrent(Document*)));
}
} else {
foreach(MultiEditor * me, mEditorList) {
disconnect(me, SIGNAL(currentDocumentChanged(Document*)),
mDocumentsDocklet, SLOT(setCurrent(Document*)));
}
}
}

This specific example isn't working (though the same works perfectly in a different context).
So I was wondering: can I established or remove connections on the fly as above?

d_stranz
5th February 2017, 17:45
Nothing wrong with that code as far as I can see. Do the member variables actually have the values you think they should?

LucaDanieli
5th February 2017, 17:50
d_stranz! You are great (and right)!
mDocumentDocklet is (slightly) the wrong class, as I need a subclass. Thanks!