[opensuse-programming] PyQt4: connect calls slot-method with some argument
Hi, I'm trying to connect widget with my own method. Using such implementation I get success: self.action_wired = QAction(QIcon("images/wired.png"), Interface, self) self.trayMenu.addAction(self.action_wired) self.connect(self.action_wired, SIGNAL("triggered()"), self.wired) ... def wired(self): print hello but I want to call "self.wired" with parameter/argument. Such call is failed: self.connect(self.action_wired, SIGNAL("triggered()"), self.wired(Interface)) TypeError: arguments did not match any overloaded call: QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType' QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType' QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType' Method "wired" should get information about interface: def wired(self, Interface): print Interface So, the question is pretty easy: how to call method via "connect" with argument? Is it really possible? Using such call, but not as one of connect's parameters, it works well: self.wired(Interface). Thank you Alex -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
On 2013-02-13 00:40:04 +0100, Alex Naumov wrote:
self.action_wired = QAction(QIcon("images/wired.png"), Interface, self) self.trayMenu.addAction(self.action_wired) self.connect(self.action_wired, SIGNAL("triggered()"), self.wired) ... def wired(self): print hello
but I want to call "self.wired" with parameter/argument. Such call is failed: self.connect(self.action_wired, SIGNAL("triggered()"), self.wired(Interface))
self.wired(Interface) is a method call which returns None which is passed as the third argument to the connect method. Something like this should work: self.connect(self.action_wired, SIGNAL("triggered()"), lambda: self.wired(Interface))
TypeError: arguments did not match any overloaded call: QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType' QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType' QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
Method "wired" should get information about interface:
def wired(self, Interface): print Interface
So, the question is pretty easy: how to call method via "connect" with argument? Is it really possible?
I've never used pyqt so I don't know if there's a better/more elegant way...
Using such call, but not as one of connect's parameters, it works well: self.wired(Interface).
Marcus -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
On Wed, Feb 13, 2013 at 2:11 AM, Marcus Hüwe
On 2013-02-13 00:40:04 +0100, Alex Naumov wrote:
self.action_wired = QAction(QIcon("images/wired.png"), Interface, self) self.trayMenu.addAction(self.action_wired) self.connect(self.action_wired, SIGNAL("triggered()"), self.wired) ... def wired(self): print hello
but I want to call "self.wired" with parameter/argument. Such call is failed: self.connect(self.action_wired, SIGNAL("triggered()"), self.wired(Interface))
self.wired(Interface) is a method call which returns None which is passed as the third argument to the connect method. Something like this should work: self.connect(self.action_wired, SIGNAL("triggered()"), lambda: self.wired(Interface))
Thank you Marcus! Lambda decided my problem :) I tryed lambda, but in such way: self.connect(self.action_wired, SIGNAL("triggered()"), lambda interface="eth1": self.wired(Interface)) and this failed also... Thank you again ;) -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
Am Mittwoch, 13. Februar 2013, 00:40:04 schrieb Alex Naumov:
Hi,
I'm trying to connect widget with my own method. Using such implementation I get success:
self.action_wired = QAction(QIcon("images/wired.png"), Interface, self) self.trayMenu.addAction(self.action_wired) self.connect(self.action_wired, SIGNAL("triggered()"), self.wired) ... def wired(self): print hello
but I want to call "self.wired" with parameter/argument. Such call is failed: self.connect(self.action_wired, SIGNAL("triggered()"), self.wired(Interface))
There's a new style signals and slots system, we use nowadays: self.action_wired.triggered.connect(lambda: self.wired(interface)) Much easier to write and to read.. http://pyqt.sourceforge.net/Docs/PyQt4/new_style_signals_slots.html Cheers, Pete -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
participants (3)
-
Alex Naumov
-
Hans-Peter Jansen
-
Marcus Hüwe