My program is currently divided into 2 files: one with GUI and second with code. In GUI, there's button I want to use to collect the data from text fields and put them into variables:
self.dodaj.clicked.connect(Dodaj_Ksiazke.pobierz_dane)
It's supposed to call the function "pobierz_dane". Inside the code there is class "Main" where above function is defined:
def pobierz_dane(self):
print("Pobieranie danych z formularza do zmiennych")
print(self.ui.isbn.currentText())
isbn = self.ui.isbn.currentText()
print(isbn)
As you can see I tried various ways to confirm it's working. When I start the program and click the button the first print gets displayed but not the 2nd or 3rd one, this is where program crashes with error:
Process finished with exit code -1073740791 (0xC0000409)
Text field I'm trying to get the text from is defined like this:
self.isbn = QtWidgets.QLineEdit(self.centralwidget)
self.isbn.setObjectName("isbn")
self.gridLayout_2.addWidget(self.isbn, 1, 2, 1, 1)
This is the beginning of GUI deifnition:
class Ui_Dodaj_Ksiazke(object):
def setupUi(self, Dodaj_Ksiazke):
And Main class from file with code:
class Main(QtWidgets.QMainWindow,Ui_Dodaj_Ksiazke):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
self.ui= Ui_Dodaj_Ksiazke()
self.ui.setupUi(self)
Since the first print is working I guess the button correctly calls the function. But I can't nail why it's not working for the text field as I don't get any errors when running the program.
Problem was fixed by switching from currentText() to displayText() as there is no attribute 'currentText' in QLineEdit.
isbn = self.ui.isbn.displayText()
Text is taken from text field stored correctly in variable, displayed by print() and program doesn't crash.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.