Reputation: 1538
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)
Upvotes: 7
Views: 4407
Reputation: 1
You have to wrap signal in a QObject:
class CarSocketSignal(QObject):
logSignal = Signal(str, str)
class CarSocket(QObject):
cslogSignal = CarSocketSignal()
...
def __init__(self, ...):
super(CarSocket, self).__init__()
...
This call would then be:
self.carSocket.cslogSignal.logSignal.connect(self.addToLog)
This should work...
Upvotes: 0
Reputation: 316
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.
Upvotes: 13
Reputation: 3645
I get the same error when I am trying to run your program. It looks really weird. I've found only one mention about that here but no solution. One thing I can suggest you is old-style connect
still works correctly:
self.connect(self.carSocket, SIGNAL("logSignal(str, str)"), self, SLOT("addToLog(str, str)"))
Possible it's bug of PySide. In comments people said that they don't have problem with PySide 1.1.2. I've this version too and Qt of version 4.8.4.
Upvotes: 0