whenever I click a button in the second window of my PyQt5 application that should just print the value of a QDateEdit in the GUI, it closes with the line: "Process finished with exit code -1073740791 (0xC0000409)". I figured out that the problem has something to do with the .value() method. Here's the Minimal to reproduce the bug with the Ui_Form class below:
import sys
from PyQt5 import QtWidgets
from ui.fenster import Ui_Form
app = QtWidgets.QApplication(sys.argv)
class AppendWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
self.ui.submit.clicked.connect(self.show_value)
def show_value(self):
print(self.ui.date.value())
append = AppendWindow()
append.show()
sys.exit(app.exec_())
Ui_Form:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(413, 215)
self.date = QtWidgets.QDateEdit(Form)
self.date.setGeometry(QtCore.QRect(72, 26, 321, 20))
self.date.setObjectName("date")
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(9, 26, 57, 16))
self.label.setObjectName("label")
self.age = QtWidgets.QSpinBox(Form)
self.age.setGeometry(QtCore.QRect(70, 120, 321, 20))
self.age.setObjectName("age")
self.label_2 = QtWidgets.QLabel(Form)
self.label_2.setGeometry(QtCore.QRect(10, 120, 23, 16))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(Form)
self.label_3.setGeometry(QtCore.QRect(9, 69, 27, 16))
self.label_3.setObjectName("label_3")
self.name = QtWidgets.QPlainTextEdit(Form)
self.name.setGeometry(QtCore.QRect(72, 69, 319, 21))
self.name.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.name.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.name.setObjectName("name")
self.submit = QtWidgets.QPushButton(Form)
self.submit.setGeometry(QtCore.QRect(170, 170, 75, 23))
self.submit.setObjectName("submit")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label.setText(_translate("Form", "Geburtsjahr"))
self.label_2.setText(_translate("Form", "Alter"))
self.label_3.setText(_translate("Form", "Name"))
self.submit.setText(_translate("Form", "Absenden!"))
Does anyone know how to fix this? I appreciate your help!
You need to add app.exec()
in your main code in order to start the main loop.
app = QtWidgets.QApplication(sys.argv)
app.exec()
The main loop handles all the incoming events and passes them to your GUI elements.
User contributions licensed under CC BY-SA 3.0