Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PySide / Qt : Too many arguments to connect a signal to a slot?

I'm trying to connect a custom signal (in a TCP client class) to a method that updates a log with the data sent by the server and whatnot.

Here's the declaration of the TCP client class:

class CarSocket(QObject):
    logSignal = Signal(str, str)
    ...
    def __init__(self, ...):
        super(CarSocket, self).__init__()
        ...

And the method I'm trying to connect to logSignal :

def addToLog(self, text, mode='NORMAL'):
    if mode == 'RAW':
        toAdd = text
    else:
        toAdd = "<p>{}</p> \n <hr> \n".format(text)
    self.log.logEdit.append(toAdd)

So, I write this line when initializing my application:

self.carSocket.logSignal.connect(self.addToLog)

And I get a really weird bug when I execute it:

Traceback (most recent call last):
  File "/home/ahmed/workspace/autonomee/main.py", line 286, in <module>
    window = MainWindow()
  File "/home/ahmed/workspace/autonomee/main.py", line 115, in __init__
    self.carSocket.logSignal.connect(self.addToLog)
TypeError: connect() takes exactly 3 arguments (4 given)
[Finished in 0.5s with exit code 1]

Anyone can help ?

It must be noted that I already succesfuly connected a custom signal on another class (with an int, connected to a method of the class itself) and that I have no problems connecting 'default' signals with default slots (like self.button.clicked.connect(self.edit.clear) or something similar)

like image 585
halflings Avatar asked May 14 '13 08:05

halflings


1 Answers

Just had this problem with my own code, and wanted to contribute what I (think) is the answer. You also have a function called "connect" in your CarSocket class. Try renaming that function and see what happens.

In my case one of my classes that was emitting the signal also had a "connect" function, and renaming it fixed the problem. It shouldn't have caused a problem since you call connect from the Signal() type itself, but there seems to be problems.

like image 193
Colin O'Flynn Avatar answered Oct 10 '22 23:10

Colin O'Flynn