python - Calling a Slot by QtCore.SignalMapper -


i want check users input in several qtgui.qlineedits same function different parameters. tried qtcore.signalmapper. code in test-application:

    self.signalmapper = qtcore.qsignalmapper(self)     qtcore.qobject.connect(self.lineedit_331, qtcore.signal(_fromutf8('returnpressed()')), self.signalmapper.map)     qtcore.qobject.connect(self.lineedit_341, qtcore.signal(_fromutf8("returnpressed()")), self.signalmapper.map)     self.signalmapper.setmapping(self.lineedit_331,'links')     self.signalmapper.setmapping(self.lineedit_341,'rechts')     qtcore.qobject.connect(self.signalmapper, qtcore.signal(_fromutf8("mapped(qstring)")),self.test) 

the signalmapper exists , connects return 'true' slot isn't called (the same after changing order of 'connect' , 'setmapping'). connecting lineedits signals slot works:

    qtcore.qobject.connect(self.lineedit_331, qtcore.signal(_fromutf8("returnpressed()")), self.test_1) 

what's wrong in code? help

the main thing wrong code, using ugly, error-prone, old-style syntax connecting signals, instead of new-style syntax.

here re-write of example code:

    self.signalmapper = qtcore.qsignalmapper(self)     self.lineedit_331.returnpressed.connect(self.signalmapper.map)     self.lineedit_331.returnpressed.connect(self.signalmapper.map)     self.signalmapper.setmapping(self.lineedit_331, 'links')     self.signalmapper.setmapping(self.lineedit_341, 'rechts')     self.signalmapper.mapped[str].connect(self.test) 

if you're curious why original code didn't work, it's because should have used slot in first 2 connections. should have been:

    qtcore.qobject.connect(         self.lineedit_331, qtcore.signal('returnpressed()'),         self.signalmapper, qtcore.slot('map()')) 

this because there 2 overloads of qsignalmapper.map, have needed specify 1 intended use.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -