I am having trouble creating custom signals and connecting them between classes.
Login Class
class LoginApp(Ui_Login_Win):
switch_window = QtCore.pyqtSignal()
def __init__(self):
self.window = QtWidgets.QDialog()
self.window.setFixedSize(348, 389)
self.setupUi(self.window)
self.login_btn.clicked.connect(self.validate)
sys.exit(self.window.exec_())
def validate(self):
conn = sql.connect("stocks.db")
curr = conn.cursor()
find_user = 'SELECT username, password FROM admin WHERE username = ? AND password = ?'
curr.execute(find_user, (self.username_entry.text(), self.password_entry.text()))
if curr.fetchone() is not None:
msg = QtWidgets.QMessageBox()
msg.setIcon(QtWidgets.QMessageBox.Information)
msg.setWindowTitle("Status")
msg.setText("Successful!")
msg.exec_()
self.switch_window.emit()
else:
msg = QtWidgets.QMessageBox()
msg.setIcon(QtWidgets.QMessageBox.Warning)
msg.setWindowTitle("Status")
msg.setText("Failed to Login!")
msg.exec_()
Application Class (where it switches windows)
class Application(QtCore.QObject):
def show_login(self):
self.login = LoginApp()
self.login.switch_window.connect(self.show_add)
After the user has successfully login, the program exits and does not proceed to the next window.