python - PyQt Can't get text from QlineEdit using text() -


i have qlineedit , while recovering text using code:

doc = self.lineedit_2.text()  def pushbutton_7_clicked(doc):     print(doc)  self.pushbutton_7.clicked.connect(pushbutton_7_clicked) 

i no error, prints false whether qlineedit contains text or not.

the clicked signal (see docs) passes attribute pushbutton_7_clicked callback:

void qabstractbutton::clicked(bool checked = false)

this signal emitted when button activated (i.e. pressed down released while mouse cursor inside button), when shortcut key typed, or when click() or animateclick() called. notably, signal not emitted if call setdown(), setchecked() or toggle().

if button checkable, checked true if button checked, or false if button unchecked.

so, when define callback, first argument checked boolean.

calling doc in callback definition doesn't make difference. you're not passing doc instance, here. here checked boolean, false time.

that's pure python issue.

a = 12 def b(a):     print(a) b(69) 

this prints 69, not 12. you're redefining a (doc in case) in scope of function.

besides, not make sense either write:

doc = self.lineedit_2.text() 

as executes once @ import time.

you try this. note need put callback in object bound , has reference in self.

class yourobject():      def pushbutton_7_clicked(self, checked):         print(self.lineedit_2.text())      self.pushbutton_7.clicked.connect(self.pushbutton_7_clicked) 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -