Connecting signal to slot immediately causes signal to be emitted

前端 未结 3 1228
不思量自难忘°
不思量自难忘° 2021-01-24 12:34

I am writing a program with python 3.3.3 and pyqt5. I have connected many signals and slots with no problem. This one is causing a problem. My code follows:

          


        
3条回答
  •  攒了一身酷
    2021-01-24 13:19

    Excellent answers but just want to add this explanation:

    Doing

    vendorComboBox.currentTextChanged.connect(_vendorChanged(vendorComboBox, dictVendors, modelComboBox))
    

    is the same as doing

    obj = _vendorChanged(vendorComboBox, dictVendors, modelComboBox)
    vendorComboBox.currentTextChanged.connect(obj)
    

    Now you should see that obj is not a function but the result of calling your _vendorChanged function with the 3 parameters. This means that you get the impression that the signal is immediately fired, thereby calling your function, but in fact it's just your function executing as directed. The second problem is that _vendorChanged does not return anything so obj is in fact None. Since you are trying to connect a signal to None, you get this error. The solution is given in other answers.

提交回复
热议问题