-1

How could get String(Text) from QlineEdit?
I tried Like this. myArea.getList() function is get string value and check database with string value and return List

self.a = QLineEdit()
self.b = QlineEdit()
....

self.b = self.myArea.getList(str(self.a.textChanged.connect(self.textchanged)))

def textchanged(self, text):
    self.my_edit = text

Input text in a, then a changes. read a, check data by a, b's data created, Input text in b, read b, check data by b

First, I don't know how to get QLineEdit()'s value. print QLineEdit Text works but return String.

AAEM
  • 1,837
  • 2
  • 18
  • 26
  • I don´t understand.What is "my_edit" and "myArea"?You only need return the value in textchanged function. `def textchanged(self, text):return text` – Fran Raga May 17 '16 at 08:17

1 Answers1

3

Here is a complete example how to get the value from self.a and self.b and set the values to each other. Maybe this tutorial helps you, too.

You can not use the return value of the methods self.textchangedA or self.textchangedB, so you have to make use of the member variables of the class.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging
import sys
from PyQt4 import QtGui

log = logging.getLogger(__name__)


class MyWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        super(MyWidget, self).__init__(parent)

        vbox = QtGui.QVBoxLayout(self)
        self.setLayout(vbox)

        self.a = QtGui.QLineEdit(self)
        self.b = QtGui.QLineEdit(self)

        vbox.addWidget(self.a)
        vbox.addWidget(self.b)

        self.a.textChanged.connect(self.textchangedA)
        self.b.textChanged.connect(self.textchangedB)

    def textchangedA(self, text):
        log.info("Text from a: %s", text)
        log.info("Text from b: %s", self.b.text())
        # do the processing

    def textchangedB(self, text):
        log.info("Text from b: %s", text)
        log.info("Text from a: %s", self.a.text())



def test():
    app = QtGui.QApplication(sys.argv)
    w = MyWidget()
    w.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    test()
salomonderossi
  • 2,180
  • 14
  • 20
  • Thanks.. But How could I use return value?? It used just only print 'values' not getting 'values'.. So I mean when I add new self.aReturn = self.textcahngedA -> print self.aReturn -> print out None / If I self.aRetunr = self.a.textChanged.connect(self.textchangedA) -> just bound method memory address priting out – Hyunjun Cheong May 17 '16 at 09:46
  • I really Super Thank you ! But.. I don't know how to get the self.a's string value independently out of the textchangedA method... I mean extract the QLineEdit's string value and use this value as independent value in the class. Not just print out – Hyunjun Cheong May 17 '16 at 09:59
  • with `self.a.text()` you get the string value and with `self.b.text()` you get the string value of b. Is this what you mean? – salomonderossi May 17 '16 at 10:02
  • Oh, I implement method in method!! I solve the problem!! I Really Thank for you!! Really!! THANK YOU!! – Hyunjun Cheong May 17 '16 at 10:54
  • You are welcome. If you could upvote or/and accept helpful answers other people can see what helped you most and the answerer gets some points as reward ;) – salomonderossi May 17 '16 at 11:00