0

I'm learning (by doing) python, and writing a program that will work on multiple text-files at the same time. The file-names are given in QLineEdit widgets of GUI. I wanted to add a function that checks on enter if these files exist. Being lazy I don't want to create multiple instances of check-if-exist, but to pass the QLineEdit as an argument.

Being naive I tried code below, but I get error 'QLineEdit not defined'

class My_App(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        ...
        self.ui.lineEdit_1.returnPressed.connect(self.CheckFileExist(self.ui.lineEdit_1))
        self.ui.lineEdit_2.returnPressed.connect(self.CheckFileExist(self.ui.lineEdit_2))
        ...

    def CheckFileExist(self, nameW: QLineEdit):
        print(nameW.text()) 

Can one do it in python or do I need separate functions for each lineEdit

Kris_R
  • 2,738
  • 3
  • 20
  • 21
  • change to `self.ui.lineEdit_1.returnPressed.connect(lambda: self.CheckFileExist(self.ui.lineEdit_1))` – eyllanesc Feb 08 '20 at 17:08
  • thanks ! I really tried with lambda but i tried to define some variable that should be passed along and all the time I had the 'QLineEdit not defined' error. – Kris_R Feb 08 '20 at 19:35
  • Have you imported QLineEdit: `from PyQt5.QtWidgets import QLineEdit`? – eyllanesc Feb 08 '20 at 19:38

0 Answers0