[PyQt] Beginners - signal - slots - question

Henrik Pauli henrik.pauli at gmail.com
Sat Dec 22 02:04:47 GMT 2007


On Friday 21 December 2007, Jochen Georges wrote:
> On Friday 21 December 2007 12:26:02 Henrik Pauli wrote:
> > On Friday 21 December 2007, Jochen Georges wrote:
> > > Hello,
>
>  ..snip
>
> > > Which is the right QLineEdit-Signal?
> > > 	the action should start when return is pressed, but the
> > > 	signal "returnPressed" has no parameter "QString"
> > > 	and
> > > 	textChanged(QString) or textEdited(QString) react on every single
> > > input How do i place my own method, that changes the text?
> >
> > Here's a hint that might get you going:
> >
> > Create a new slot for your own use :)  In PyQt it’s just a python method,
> > you can do anything in it.
>
> OK, that works: (but it does not look like good style, does it?)
>
> QtCore.QObject.connect(self.lineEdit,QtCore.SIGNAL("returnPressed()"),self.
>blabla)
>
> def blabla(self):
> 	#some code
>         self.lb_ergebnis.setText(myString)
>

This is fine, really!

> #---------
>
> QtCore.QObject.connect(self.lineEdit,QtCore.SIGNAL("returnPressed()"),
> 		self.lb_ergebnis, QtCore.SLOT(setText(self.blabla)))
> def blabla(self):
> 	#some code
>         return myString
>
> mmhhh ...
>
> how can i pass an argument to the slot-name?
>

You don’t.  Slots take as many arguments as they’re prepared for (in case of 
setText, one), and if the signal sends one, then it’ll work.  Okay, it’s a 
bit more complicated than that, but that’s the core idea really.

So if you wanted to do it fully signalslotted, you'd make a (py)signal which 
takes myString as an argument, connect it to setText, and emit it with 
blabla.  (Unless I'm wrong... but that’s how I remember.  Having to do Perl 
GTK stuff at work doesn’t help me keep my PyQt knowledge rustfree)

QtCore.QObject.connect(self.lineEdit,QtCore.SIGNAL("returnPressed()"),
                          self.blabla)
QtCore.QObject.connect(self, QtCore.PYSIGNAL("blabla2"),
                          self.lb_ergebnis, QtCore.SLOT("setText(QString)"))
## no () after a pysignal's name

def blabla(self):
	#some code
	self.emit( PYSIGNAL("blabla2"), (myString,) )
## N.B. the comma after the argument, that’s so it's a tuple.


>
> thanks for any hint
>
> beste gruesse
> jochen
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt





More information about the PyQt mailing list