I’m learning Pyside and I can’t seem to get text from a QLineEdit into my own method so that I can input it into a query etc. I know it has to do with lineEdit.text(), but it isn’t seeming to work. Do I need to associate it with a signal before the text will go into my variable??
This is the type of thing I’ve been trying. Do I need a textChanged signal to get it to update or something?? I’ve tried adding self.line , but that didn’t work either, a little rusty on object oriented programming.
line=QtGui.QLineEdit(self)
myVar = line.text()
A short code example would be great. Thanks!
You seem to be creating the object and using it right afterwards. Of course, you get an empty string from
text(); it doesn’t work like that.You should add the
QLineEditto a GUI, let the user do something with it and then obtain the text withQLineEdit.text(). To know when exactly the user changed the text, yes, you should connect to theQLineEdit.textEditedslot.Here is a full example that uses such a mechanism to copy all the text from a
QLineEditto aQLabelas soon as it’s modified.This is example shows how you can connect your own function to a slot. But since a
QLabelhas asetTextslot, we could just doself.line_edit.textChanged.connect(self.line_edit.setText)and not define a function.P.S. You really should read some tutorial; I found this one very useful.