disconnect widgets? " failed to disconnect"
Hello,
I'm trying to disconnect widgets but I don't manage to do so. I probably don't use the right commands. I have tested a few of them, but there must be a mistake. Does anybody see what I'm doing wrong here?
Here is an example of what happens (I made it short, initial version is much longer). The function I connect is here a simple message saying you're still connected. I have 2 loops, the first one supposed to connect, the second to disconnect. In my real script the second loop will be activated by a signal. But I don't manage to disconnect :(
edit : in details:
wMywidget[k].textChanged.disconnect( wMywidget[k], functionForThisWidget ) leads to an error, so you can remove this line if you test it.
The other disconnect(....) don't seemm to diconnect.
var n = 3;wDial = new DzBasicDialog();wBox = new DzVGroupBox(wDial);var wMywidget = new Array;for (k=0; k<n; k++){ wMywidget[k] = new Array;wMywidget[k] = new DzLineEdit(wBox);wMywidget[k].text = "my text"+k;connect(wMywidget[k], "textChanged(const QString&)", functionForThisWidget);}for (k=0; k<n; k++){disconnect(wMywidget[k], "textChanged(const QString&)", functionForThisWidget);disconnect(wMywidget[k], "textChanged(const QString&)");disconnect(wMywidget[k], "textChanged(const QString&)", 0, 0);disconnect(wMywidget[k], "textChanged()", functionForThisWidget);disconnect(wMywidget[k], "textChanged()");disconnect(wMywidget[k]);wMywidget[k].textChanged.disconnect( wMywidget[k], functionForThisWidget ) // you can remove this lines it leads to an error}function functionForThisWidget(){ print("Still connected") }wDial.addWidget (wBox);wDial.exec()
Comments
I can confirm that the problem is reproducable on my system (Studio v4.8.0.59, Win7 64bit).
There may be a problem with DzLineEdit.textChanged.disconnect() ???
In the context of your code:
wWidget = new DzLineEdit( wBox );
// This causes no error, and has the desired effect:
wWidget.textChanged.connect( functionForThisWidget );
// This causes an error, even though it is the exact equivalent of the ".connect()" that works OK above:
// Error: Function.prototype.disconnect: failed to disconnect from DzLineEdit::textChanged(QString)
wWidget.textChanged.disconnect( functionForThisWidget );
// These both cause no error, but do not actually disconnect: functionForThisWidget() continues to be called:
disconnect( wWidget, "textChanged(const QString&)", functionForThisWidget );
disconnect( wWidget, "textChanged(const QString)" , functionForThisWidget );
There does appear to be a bug with disconnecting signals at the moment. I tweaked your sample to make it easier to read and I added some debugging to better visualize what is happening:
I'm running it in the debugger and stepping through the Qt source. I haven't found where the issue is yet, but I know its there. It appears to have been an issue at least as far back as 4.5.0.114 4.0.2.55 3.1.2.32.
-Rob
Thanks for the feedback Rob and Praxis! Indeed, Rob, it is a better way to see if the "disconnect" is done.
I hope you will be able to find out what goes wrong, which won't be easy I guess.
On my side, I never managed to disconnect of course, but I managed to rewrite some small parts of my script in a way that I don't need to disconnect any more.