disconnect widgets? " failed to disconnect"

V3DigitimesV3Digitimes Posts: 3,150

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

 

Post edited by V3Digitimes on

Comments

  • PraxisPraxis Posts: 247

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

     

  • rbtwhizrbtwhiz Posts: 2,250
    edited May 2016

    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:

    function printText(){	print( this.name, "=", this.text );}var wDlg = new DzBasicDialog();var wBox = new DzVGroupBox( wDlg );var nWidgets = 3;var wMyWidgets = new Array( nWidgets );var wLineEdit;var bResult;// for( var i = 0; i < nWidgets; i += 1 ){	wLineEdit = new DzLineEdit( wBox );	wLineEdit.name = "LineEdit" + i;	wLineEdit.text = Math.random();	bResult = wLineEdit.textChanged.connect( wLineEdit, printText );	wMyWidgets[i] = wLineEdit;		print( wLineEdit.name, "connect =", bResult );}wDlg.addWidget( wBox );wDlg.exec();for( var i = 0; i < nWidgets; i += 1 ){	wLineEdit = wMyWidgets[i];	bResult = disconnect( wLineEdit, "textChanged(const QString&)", printText );	//bResult = disconnect( wLineEdit, "textChanged(QString)", printText );	//bResult = disconnect( wLineEdit, "textChanged()", printText );	//bResult = disconnect( wLineEdit, "textChanged", printText );	//bResult = wLineEdit["textChanged(const QString&)"].disconnect( printText );	//bResult = wLineEdit["textChanged(QString)"].disconnect( printText );	//bResult = wLineEdit.textChanged.disconnect( printText );		print( wLineEdit.name, "disconnect =", bResult );}wDlg.exec();

    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

    Post edited by rbtwhiz on
  • V3DigitimesV3Digitimes Posts: 3,150
    edited May 2016

    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.

    Post edited by V3Digitimes on
Sign In or Register to comment.